Does anyone know how to delete all VB code form an Excel workbook using C#? This code doesn’t work. It removes first (last one) VBComponent, but rises ArgumentException on second one.
VBProject project = workbook.VBProject;
int componentsCount = project.VBComponents.Count;
for (int i = componentsCount; i >= 1; i--)
{
VBComponent component = project.VBComponents.Item(i);
project.VBComponents.Remove(component);
}
Any suggestions? :)