Delete modules in another file

  • Thread starter Thread starter MikeP
  • Start date Start date
M

MikeP

I am having trouble running a macro that deletes a module in another
file. The script I'm using is:

Sub DeleteModules()
Dim VBComp As VBComponent

Set VBComp = ThisWorkbook.VBProject.VBComponents("Module2")
ThisWorkbook.VBProject.VBComponents.Remove VBComp

End Sub

Before I run the macro I activate a tab within the desired workbook.
Any idea why this is giving me a subscript out of range error?
 
Mike,

You'll need to change both instances of

ThisWorkbook

to

ActiveWorkbook


HTH,
Bernie
MS Excel MVP
 
Back
Top