No success deleting modules

  • Thread starter Thread starter BrianG
  • Start date Start date
B

BrianG

I have three modules in a worksheet. I'm calling a Sub in Module3 which
needs to delete Module1 and Module2 then save the wookbook. The only
time it works is if I run it standalone. If it's called, the modules
aren't removed. I considered deleting all vbComponents but I need
Module3 left intact to transfer control to a new workbook. Maybe I need
to somehow transfer control to a Sub in Module3 rather than call it.
Thoughts?

The called Sub in Module3 is coded as follows:

Sub DelModules()
Dim VBComp1 As VBComponent
Dim VBComp2 As VBComponent
Set VBComp1 = ThisWorkbook.VBProject.VBComponents("Module1")
Set VBComp2 = ThisWorkbook.VBProject.VBComponents("Module2")
ThisWorkbook.VBProject.VBComponents.Remove VBComp1
ThisWorkbook.VBProject.VBComponents.Remove VBComp2
End Sub
 
If you try to save the workbook before the code thread that deletes the
modules completes, then it will be saved with the modules intact. You might
try using application.Ontime to break this thread. Do the save in the code
that the ontime executes.
 
Back
Top