ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Module still there even after remove and save (https://www.excelbanter.com/excel-programming/376343-module-still-there-even-after-remove-save.html)

shurstgbr

Module still there even after remove and save
 
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.)


Peter T

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.)





All times are GMT +1. The time now is 06:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com