Results 1 to 10 of 10
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can you find the code called behind a button

    I have inherrited many templates.
    There are custom menus & buttons on the toolbar.
    How do I track down & determine the code called from the buttons?

    I've searched through the modules for related code but to no avail.
    TIA Diana

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How can you find the code called behind a button

    Diana, you haven't mentioned the application or version. This code works in Word 2000- it's a starting point anyway:

    Dim cb As CommandBar
    Dim cbc As CommandBarControl

    For Each cb In Application.CommandBars
    For Each cbc In cb.Controls
    If Not cbc.BuiltIn Then
    Debug.Print cbc.OnAction; " "; cbc.Caption
    End If
    Next
    Next
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How can you find the code called behind a button

    Geoff
    The application is Word 97 - VBA
    Diana

  4. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How can you find the code called behind a button

    Diana,

    Thanks for that.

    I've just checked the code in Word 97- it does work, and puts the name of any routines in the debug window. You can make it a little more informative by showing the name of the toolbar and the position of the button in that toolbar:

    Dim cb As CommandBar
    Dim cbc As CommandBarControl

    For Each cb In Application.CommandBars
    For Each cbc In cb.Controls
    If Not cbc.BuiltIn Then
    Debug.Print cb.Name; " "; cbc.Index; cbc.OnAction; " "; cbc.Caption; cb.Name
    End If
    Next
    Next


    Although the "Index" might not be accurate, if there's invisible buttons for instance.

    Let me know if that helps.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  5. #5
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How can you find the code called behind a button

    Diana: This works in Excel 2000. First, right click on the button and from the pop up menu choose "Customize." This should bring up the Customize dialog box. With this dialog box displayed, click on the button again and in the pop up menu select "Assign macro." In the resulting dialog box, the name of the macro assigned to the button should be in the text box at the top of the dialog.
    Legare Coleman

  6. #6
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How can you find the code called behind a button

    Legare,

    Thanks for showing the easy way! I'd looked at the customize, but didn't know about seeing the macro name in the "Assign macro" button.

    Word works differently in the customize; one of the annoying differences between Word and Excel.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How can you find the code called behind a button

    Legare
    Unfortunately Word doesnt have this feature or ability to view macros/code.
    Thanks Diana

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How can you find the code called behind a button

    You can view macros/code in the Visual Basic Editor (Tools->Macros->Visual Basic Editor), but figuring out what was assigned to a menu item is difficult, especially since Word doesn't seem to expose the properties collection of the toolbar/menu items. For instance, if you create a macro and use customize to assign it to a toolbar, you can change the name that shows up on the toolbar and it will still call the correct macro. Unfortunately, you can't necessarily tell which one it's calling anymore.
    Charlotte

  9. #9
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: How can you find the code called behind a button

    Word doesn't expose the toolbar controls properties, directly within the user interface, but it does does so in VBA (the commandbar-related properties and methods, available via code, are fairly amazing).

    The macro Geoff posted earlier in this thread, does provide this information.

  10. #10
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How can you find the code called behind a button

    Sigh. It would be nice if Microsoft's designers/developers talked to each other occasionally. The information should be available from VBA code and is the only other way I can think of at the moment.
    Legare Coleman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •