# Solved: Vba: Can A Macro Delete A Module?



## balloon_tom (Jan 5, 2006)

I have an Excel 2003 PRO workbook whick contains several VBA modules. One of these modules is used as a "startup" program which creates additional worksheets, graphs etc. within the workbook. I call this startup module from a macro in a different module only the first time the workbook is opened. Once this startup module has run, I would like the calling macro to remove this entire starup module from the workbook prior to saving the newly expanded workbook. Is this possible?
Thanks, Tom


----------



## OBP (Mar 8, 2005)

In VBA use the following - 

DoCmd.DeleteObject acModule, "module name"


----------



## cristobal03 (Aug 5, 2005)

I'm not sure that will work. *acModule* is an Access constant not an Excel constant. Also, the *DoCmd* object doesn't show up in Excel's object browser. My Excel VBA is really weak though; maybe I'm not looking in the right spot.

chris.


----------



## OBP (Mar 8, 2005)

Chris, you may well be right, I forgot to switch thinking caps. I would think there must be an Excel version though, I will consult my books.


----------



## OBP (Mar 8, 2005)

It looks as if you may be right Chris, Excel's help doesn't mention working with "Modules" at all.


----------



## OBP (Mar 8, 2005)

I was wrong, I found this in Excel 2000 Power Programming 

With ActiveWorkbook.VbProject
.VBComponents.Remove . VBComponents("Module1")
End With

to remove module1


----------



## balloon_tom (Jan 5, 2006)

Please forgive me folks, I had to go out of town for a few days. This works lika a champ!! Once again *YOU FOLKS ROCK!!*
Tom


----------

