Computer geek, and self-appointed know-it-all, Westley Annis answers all those hard 

questions about anything related to computers and technology, as well as business and 

political questions.

What macro is a menu item pointing to?

I've got a bunch of custon menu entries on my menu bar but I don't know which macro they point to. How can I find out?

Word is a powerful word processor that simplifies a lot of steps by using wizards and point-and-click type commands. Programmers and power-users can add even more powerful features to Word by writing special functions in Visual Basic for Applications (VBA) that performs functions that may be specialized to a particular need.

When done in a company setting, these features may be added to Word's menu bar to make it easier for users to find these commands.

While this is a great feature, it can cause a few problems if the original programmer is no longer available to maintain the code and he didn't leave any comments as to which menu items called which functions. This is where Word's point-and-click interface is deficient.

However, you can use VBA to make up for that deficiency. The macro listed below will create a list in the currently active document that lists every menu bar and tool bar, Command Bars in Microsoft speak, available to Word. It will then list every item on those Command Bars and which macro, if any, the item points to.

Public Sub CommandBarNames()
' Written by Westley Annis
' http://www.AskWestley.com

Dim cbBar As CommandBar, ctControl As CommandBarControl
Dim ctControl2 As CommandBarControl

For Each cbBar In Application.CommandBars
    Selection.TypeText "CommandBar: " & cbBar.Name
    Selection.TypeParagraph
    For Each ctControl In cbBar.Controls
        Selection.TypeText "Control: " & ctControl.Caption
        Selection.TypeParagraph
        If Not ctControl.BuiltIn Then
            Selection.TypeText "     " & ctControl.OnAction
            Selection.TypeParagraph
        End If
        If ctControl.Type = msoControlPopup Then
            For Each ctControl2 In ctControl.CommandBar.Controls
                Selection.TypeText "          " & ctControl2.Caption
                Selection.TypeParagraph
                If Not ctControl2.BuiltIn Then
                    Selection.TypeText "                " & ctControl2.OnAction
                    Selection.TypeParagraph
                End If
            Next ctControl2
        End If
    Next ctControl
Next cbBar
End Sub


Category is Microsoft Office   (Article #10)
Comments

Thank you for the answer. Since I have VBA that installs menu items, I should have thought of it. I just did believe they had a UI to allow adding, but not for changing.

Thanks again,
Peyton

Posted by: Peyton King at August 9, 2005 :09 PM
This site is incredible!
This site is incredible! It's amazing the questions you get asked and you always come up with the answer. I've just got to help you stay cool by buying you a Snoball!
I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited
email, period. I hate it just as much as you do.

Also note that by submitting a question or comment
you're agreeing to relinquish any subsequent rights of
ownership to your material by submitting it on this site.









Ask Westley your question on technology, business, or politics!
RDF XML
Add to My Yahoo!
Subscribe in 
NewsGator Online
Feedburner
Search



All Categories
Archives by Category
Book Links
Powered by
Movable Type 3.17
© 2005 by Westley Annis. All Rights Reserved.

Valid XHTML 1.0!