View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Delete a macro using a macro

Why not add the macro in a sperate module ?

See this page for delting a macro
http://www.cpearson.com/excel/vbe.aspx


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"StephenT" wrote in message ...
Thanks Rob

Unfortunately no joy there.

The code works if I record a new macro called Module1 (the macro calls
itself 'myworksheet.xls'!Module1.Module1). The code then deletes that new
module.

But if I try to replace the "Module1" with my own macro that I want to
delete "deleteme1" then it doesn't work i.e. :

Sub RunMacroAndDeletModule()
MsgBox "By deleteme1"
With ThisWorkbook.VBProject.VBComponents
.Remove .Item("deleteme1")
End With
End Sub

Any advice for killing my macro called "deleteme1"? I also have other macros
that I don't want deleted at the same time

thanks
S

"Ron de Bruin" wrote:

Hi StephenT

Try this if "Trust access to VBA project object model" is checked if the macro is in Module1


Sub RunMacroAndDeletModule()
MsgBox "By module1"
With ThisWorkbook.VBProject.VBComponents
.Remove .Item("Module1")
End With
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"StephenT" wrote in message ...
Hello, I have written a macro to clean my workbook before publishing, and I
would like to delete a macro using this macro.

Can someone please help with the code to delete a macro?

This won't break the internet will it?