deleting macros

S

SLG

Is there a way to delete ALL macros from existing Excel
workbooks without deleteing each one individually?
 
B

Bernie Deitrick

SLG,

Requires a reference to the MS VBA extensibility, and acts on the
activeworkbook, but that is easy enough to change:

Sub RemoveAllVBACode()

Dim myVBA As VBIDE.VBComponent

For Each myVBA In ActiveWorkbook.VBProject.VBComponents
If myVBA.Type = vbext_ct_Document Then
With myVBA.CodeModule
.DeleteLines 1, .CountOfLines
End With
Else
ActiveWorkbook.VBProject.VBComponents.Remove myVBA
End If
Next myVBA
End Sub

HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top