Easy count of custom menuitems that perform an action (macro)

R

Robert Avery

In case anyone else would like to find out how many custom menuitems
they have made...

Sub CountAllCustomMacrosInExcel()
Dim cb As Office.CommandBar
Dim CBC As Office.CommandBarControl
Dim count As Long

For Each cb In Application.CommandBars
For Each CBC In cb.Controls
RecursiveCountMacroButtons CBC, count
Next
Next

Debug.Print count
End Sub


Public Function RecursiveCountMacroButtons(CBC As
Office.CommandBarControl, ByRef count As Long)

Dim cbp As Office.CommandBarPopup
Dim cbb As Office.CommandBarButton
Dim ncbc As Office.CommandBarControl


If TypeOf CBC Is Office.CommandBarPopup Then
Set cbp = CBC
For Each ncbc In cbp.Controls
RecursiveCountMacroButtons ncbc, count
Next
ElseIf TypeOf CBC Is Office.CommandBarButton Then
Set cbb = CBC
If Not cbb.BuiltIn Then
If Len(cbb.OnAction) Then
count = count + 1
'Cells(count + 2, 1) = cbb.OnAction
End If
End If
End If

End Function
 

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