Reputation: 127
I use two macros in my workbook as there are some data manipulation required in between macros.
I can run Macro 1 and save the file as a *.xlsm and after data manipulation, need to run Macro 2.
I want to know the possibility of Remove Macro 1 before saving?
Upvotes: 0
Views: 1224
Reputation: 2327
Probably easiest way is to store the macro in a separate module, and this code removes the entire module:
Sub DeleteModule()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("Module1")
VBProj.VBComponents.Remove VBComp
End Sub
This code is from www.cpearson.com/excel/vbe.aspx , where you can find other useful information too.
Upvotes: 1