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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,213,543
Messages
6,114,236
Members
448,555
Latest member
RobertJones1986

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