ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Easy count of custom menuitems that perform an action (macro) (https://www.excelbanter.com/excel-programming/423990-easy-count-custom-menuitems-perform-action-macro.html)

Robert Avery

Easy count of custom menuitems that perform an action (macro)
 
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


All times are GMT +1. The time now is 09:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com