Check if a Macro is assigned

FortyTwo

New Member
Joined
Jun 16, 2008
Messages
21
Hello,

I've been assigned to work with a file that has changed hands many times. In this file there are multiple macros contained in multiple modules.

What I'd like to find out is which of these macros are actually being used by the file. Is there any way to find out which macros are assigned in a workbook without checking each individual button?

Thank you,

Fortytwo
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Sorry no. The macros could be assigned to all sorts of objects, eg a Button, a Shape or a Toolbar Control. There is no way of finding out what object (if any) a macro is assigned to.
 
Upvote 0
What I'd like to find out is which of these macros are actually being used by the file. Is there any way to find out which macros are assigned in a workbook without checking each individual button?
The big problem you will have is that there are a lot of ways to run macros, where a button would not be involved at all. And maybe by "button" you mean a command button from the control toolbox, which has a click even procedure, not a macro assigned to it.

If you are only interested in the Forms buttons on worksheets, and you want to check which macros are being used by those particular buttons and attack the situation that way, albeit in a very limited fashion, this would do what you literally say you want, but again, even if all those buttons were removed, it would not stop anyone from running a macro a different way, hence as you say still "being used by the file".

Code:
Sub Test1()
Dim btn As Button, wks As Worksheet
For Each wks In Worksheets
For Each btn In wks.Buttons
MsgBox btn.OnAction
Next btn
Next wks
End Sub
 
Upvote 0
Sorry, too late to edit as I thought that just seeing macro names would not tell you much, so here's the worksheet and button name that goes with each assigned-to-Forms button macro:

Code:
Sub Test1()
Dim btn As Button, wks As Worksheet
For Each wks In Worksheets
For Each btn In wks.Buttons
MsgBox _
"Sheet name:" & vbTab & wks.Name & vbCrLf & _
"Button name:" & vbTab & btn.Name & vbCrLf & _
"Macro name:" & vbTab & btn.OnAction, , "Sheet button macros"
Next btn
Next wks
End Sub
 
Upvote 0
Sorry, too late to edit as I thought that just seeing macro names would not tell you much, so here's the worksheet and button name that goes with each assigned-to-Forms button macro:
Old thread, but I replaced "Buttons" by "Shapes" to include other objects that can have macro assigned (like Label, Textbox...). Shapes also include buttons.
Code:
Sub ListAllMacroUsage()
    Dim shp As Shape, wks As Worksheet
    For Each wks In Worksheets
        For Each shp In wks.Shapes
            If shp.OnAction <> "" Then
                Debug.Print "Sheet: " & wks.Name & vbTab & "Name: " & shp.Name & vbTab & "Macro: " & shp.OnAction
            End If
        Next shp
    Next wks
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,647
Messages
6,173,544
Members
452,520
Latest member
Pingaware

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