View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Module still there even after remove and save

This worked for me

' in Module2
Sub test()
Dim oComp As Object
Set oComp = ThisWorkbook.VBProject.VBComponents("Module2")
ThisWorkbook.VBProject.VBComponents.Remove oComp
[a1] = ThisWorkbook.VBProject.VBComponents.Count ' 6
ThisWorkbook.Save
Application.OnTime Now, "saveme"
End Sub


'in Module1
Sub saveme()
[a2] = ThisWorkbook.VBProject.VBComponents.Count ' 5
ThisWorkbook.Save
End Sub

The point being the module is only removed after all code in it terminates

Regards,
Peter T


"shurstgbr" wrote in message
oups.com...
I'm running some code in a module and then removing the module using
ThisWorkBook.VBProject.VBComponents.Remove etc. I then save the file
using ThisWorkBook.Save. However, if I dont save the file on closing
when prompted by excel then when I reopen the file the module is still
there!! What am I doing wrong?? (The module is removed if I save at the
excel prompt.)