Transfer control to new module in macro

B

BrianG

I need to delete all macros and vbComponents on save. I'm able to
perform all the vb Component deletions but I can't figure out how to
transfer control to a new module that deletes all other modules. All is
well when I execute the Delete_Macros module by itself but my attempts
at transferring control to it from the Delete_vbComponents module result
in the calling module not being deleted. What am I missing?

BrianG



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

jaf

Hi Brian,
You can't delete the code module that the code is running in no matter where
it is.

A possible solution would be to open another workbook.
Use application.run to run a code module in wb2 that deletes the modules in
wb1 and then closes.
 
B

BrianG

jaf said:
You can't delete the code module that the code is running in no matter where
it is.

I have my Auto_Open sub in Module1. I then call a Sub in Module2 to
delete Module1. If I run the Sub by itself, Module1 gets deleted but
if let Module1 call the Sub in Module2, Module1 does not get deleted.
I need to automatically delete the Auto_Open sub so that it doesn't
run on subsequent opens.

If I can't cut the ties to Module1 so that it can be deleted by a Sub
in Module2, is opening another workbook the only way?

BrianG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top