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?

Question asked on August 8, 2005 11:22 PM :: :: Comments (0)

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


Categories

Leave a comment




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



All Categories
Powered by
Movable Type 4.1
© 2005-2009 by Westley Annis. All Rights Reserved.

Valid XHTML 1.0!