Macro to delete a macro?

robfo0

Active Member
Joined
Feb 19, 2002
Messages
281
Hi again,

I have a macro which I want to run one time, then delete it with code.

I was thinking have 2 macros, then when the one i want to delete runs, at the end ill add "Call deletemacro" which will call the 2nd macro to delete the first.

Does anyone have the code to delete a module of code from within vb?

Thanks :)
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi al,
Thanks for the link, i added the reference and tried this code:
Sub Delete_Save()
Dim VBComp As VBComponent
Set VBComp = ThisWorkbook.VBProject.VBComponents("SaveMacro")
ThisWorkbook.VBProject.VBComponents.Remove VBComp
End Sub

but im getting the error "Programmic access to Visual Basic Project is not trusted".

is there a way to get around this?

thanks
 
Upvote 0
Yes. In tools > Macro > security, you can change this. Go to Trusted Sources tab and check the box for Trust Access to Visual Basic Project.
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,457
Members
448,898
Latest member
drewmorgan128

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top