View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Fan924 Fan924 is offline
external usenet poster
 
Posts: 238
Default 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