deleting macros

  • Thread starter Thread starter SLG
  • Start date Start date
S

SLG

Is there a way to delete ALL macros from existing Excel
workbooks without deleteing each one individually?
 
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
 
Back
Top