![]() |
Delete a macro using a macro
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? |
Delete a macro using a macro
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? |
Delete a macro using a macro
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? |
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? |
Delete a macro using a macro
Oh I get it... Put all the macros you need to delete in their own module,
then delete the module using your original code. Works now, thanks! "Ron de Bruin" wrote: 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? |
All times are GMT +1. The time now is 11:58 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com