Delete modules in another file

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?
 
B

Bernie Deitrick

Mike,

You'll need to change both instances of

ThisWorkbook

to

ActiveWorkbook


HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top