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?