ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   No success deleting modules (https://www.excelbanter.com/excel-programming/279898-no-success-deleting-modules.html)

BrianG[_4_]

No success deleting modules
 
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

--
BrianG

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Tom Ogilvy

No success deleting modules
 
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.

--
Regards,
Tom Ogilvy

BrianG wrote in message
...
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

--
BrianG

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!





All times are GMT +1. The time now is 11:12 AM.

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