jerry12302
Active Member
- Joined
- Apr 18, 2005
- Messages
- 456
- Office Version
- 2010
- Platform
- Windows
I have the below VBA code to remove all macros from a workbook, but of course this macro remains.
Is there a way to remove all macros and also remove this macro after it is done, so there are no macros left at all?
Sub remove_macros()
Dim m As Object
Dim mCtr As Integer
Dim oCtr As Variant
Dim vbP As Object
Dim strNames As String
strNames = ThisWorkbook.Name
mCtr = 0
Set vbP = Workbooks("" & strNames).VBProject.VBComponents
For oCtr = 1 To vbP.Count
mCtr = mCtr + 1
If vbP(mCtr).Type = 1 Then
Set m = vbP
m.Remove vbcomponent:=m.Item(m(mCtr).Name)
mCtr = mCtr - 1
End If
Next
End Sub
Is there a way to remove all macros and also remove this macro after it is done, so there are no macros left at all?
Sub remove_macros()
Dim m As Object
Dim mCtr As Integer
Dim oCtr As Variant
Dim vbP As Object
Dim strNames As String
strNames = ThisWorkbook.Name
mCtr = 0
Set vbP = Workbooks("" & strNames).VBProject.VBComponents
For oCtr = 1 To vbP.Count
mCtr = mCtr + 1
If vbP(mCtr).Type = 1 Then
Set m = vbP
m.Remove vbcomponent:=m.Item(m(mCtr).Name)
mCtr = mCtr - 1
End If
Next
End Sub