Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find which macros are assigned to toolbar 1

Status
Not open for further replies.

Nelviticus

Programmer
Sep 9, 2003
1,819
GB
A previous employee created a Word Add-In that gets installed in Word's Startup folder. It consists of a toolbar with a lot of code behind it.

Is there an easy way to find out which macro is assigned to a particular toolbar button? When you first assign a macro to a button the button's name is that of the macro, but if you change this to something more friendly (as he did) there doesn't seem to be an obvious way of finding out which function the button links to.

There are literally hundreds of functions. I could put a breakpoint in every single one of them then click every one of the toolbar buttons to see which function runs, but that would take me ages - is there another way? We use Word 2002.

Thanks

Nelviticus
 
Yes. But only to the Module/Procedure level.
Code:
MsgBox CommandBars("Menu Bar").Controls("Lah De Dah").OnAction
will display the procedure called by the control named Lah De Dah.

For my test of this, I have a Sub named LoopAllDocs, in a module named modUtilities, in a global template. So, that file is NOT loaded as a file.

I put the Sub up onto the Menu Bar toolbar (to the right of Help. Right clicked it, and gave it the Name: Lah De Dah.

The code above displayed:

modUtilities.LoopAllDocs

Note: it does NOT, repeat NOT, give the Project name!

So another button (named MyBookmarks) on the toolbar (firing Sub GetBookmarks) will return:

Module1.GetBookmarks

This does NOT indicate that it is from Normal.dot, just like the previous example - modUtilities.LoopAllDocs - does not indicate it is from my global template VBAXTools.dot.

I know of no way to get the full project/module/procedure "path".

Hope this helps.

faq219-2884

Gerry
My paintings and sculpture
 
Fumei, you're a star, so have one!

Here's the code I ended up using - if I was being clinical I'd test for the existence of the named toolbar but I couldn't be bothered:

Code:
Public Sub ToolbarMacros()
    
    On Error GoTo Err_ToolbarMacros
    
    Const sTOOLBAR As String = "HR Toolbar"
    
    Dim sList As String
    Dim sLine As String
    Dim oControl As CommandBarControl
    
    For Each oControl In CommandBars(sTOOLBAR).Controls
        
        sLine = oControl.Caption + ":" + vbTab + oControl.OnAction + vbCr
        sList = sList + sLine
        
    Next
    
    MsgBox Prompt:=sList, Buttons:=vbOKOnly, Title:="Macros linked from " + sTOOLBAR
    
Exit_ToolbarMacros:
    
    Exit Sub
    
Err_ToolbarMacros:
    
    Resume Exit_ToolbarMacros
    
End Sub

Regards

Nelviticus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top