![]() |
Deleting macros by running a macro?
I tried to record a macro being deleted and nothing recorded.
|
Deleting macros by running a macro?
I posted an explanation of a way to do this in this message:
http://www.mrexcel.com/forum/showthr...elf-destruct#3 -- "Actually, I *am* a rocket scientist." -- JB Your feedback is appreciated, click YES if this post helped you. "Fan924" wrote: I tried to record a macro being deleted and nothing recorded. |
Deleting macros by running a macro?
Hi,
Be careful how you use this, there's no going back if you save the workbook. This code can delete the module it's in (a sort of code suicide) or run from another module delete that one. Chane the last line to the name of the module to delete. Sub Death_To_Code() Dim ThisModule As Object Set ThisModule = Application.VBE.ActiveVBProject.VBComponents ThisModule.Remove VBComponent:=ThisModule.Item("Module2") End Sub Mike "Fan924" wrote: I tried to record a macro being deleted and nothing recorded. |
Deleting macros by running a macro?
I found this from 2000
Sub OpenFileAndDeleteModule() Application.ScreenUpdating = False Workbooks.Open "C:\Excel\book1.xls" With ActiveWorkbook.VBProject .VBComponents.Remove .VBComponents("Module1") End With ActiveWorkbook.Save ActiveWorkbook.Close End Sub |
Deleting macros by running a macro?
I have been playing with this. From the archives. Deletes all macros.
Sometimes it deletes itself, sometimes it does not.Can it be fixed so it always deletes itself? Sub DeleteAllMacros() Dim Composantvbe As Object With ThisWorkbook.VBProject For Each Composantvbe In .VBComponents If Composantvbe.Type = 100 Then With Composantvbe.CodeModule .DeleteLines 1, .CountOfLines .CodePane.Window.Close End With Else: .VBComponents.Remove Composantvbe End If Next Composantvbe ActiveWorkbook.Save ActiveWorkbook.Close End With End Sub |
All times are GMT +1. The time now is 01:19 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com