macro to delete all macros?

Myke

New Member
Joined
Jan 23, 2003
Messages
39
I have a directory with about 300+ files with macro's attached to them. Any macros on the sheets are completely redundant and we have to remove them. However, opeining them individually and removing any macros is a VERY tedious process. Can I do this automatically in any way (i.e. create a button on the taskbar which will delete any and all macro's on the active sheet.

This would save me Sooooooo much time.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi Myke

This code will delete modules from your workbook.

Code:
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

You will need to explicitly save each workbook after the modules are removed. Saving in code has no effect (??? - Odd I know).

If you have code in sheets or forms etc then change the

If vbP(mCtr).Type = 1 Then

line to recognise other types of objects. The Visual Basic Help has all the details (from the VBProject Collection).

Try it!

anvil19
:o
 
Upvote 0

Forum statistics

Threads
1,223,627
Messages
6,173,417
Members
452,514
Latest member
cjkelly15

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top