Results 1 to 5 of 5
  1. #1
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Passing arguments to toolbar macros (Word 2002 SP-2)

    I realize there are workarounds (creating a separate specific macro, using CommandBars.ActionControl.Tag, etc.), but in Word 2002 is there a straightforward way for the OnAction of a toolbar button to call a procedure and pass it one or more arguments?

    I've found a few web pages that purport to offer solutions (using combinations of single- and double-quotes, or using the .Parameter property of the button), but none of them seem to work for me in Word 2002.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing arguments to toolbar macros (Word 2002 SP-2)

    The Parameter property of a command bar control acts like a second Tag property. It does not get passed automatically, but the OnAction macro can pick it up the same way it can pick up the Tag (CommandBars.ActionControl.Parameter)

    It's rather strange that the Office applications have different ways of implementing command bars:
    In Access, you can use .OnAction = "MyMacro(MyArgument)"
    In Excel, you can use a construction with single and double quotes.
    In Word, none of those work. You cannot pass a real parameter to the .OnAction procedure.

  3. #3
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Passing arguments to toolbar macros (Word 2002 SP-2)

    Thanks for the prompt response. The fact that it's easy in Access is some consolation.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Passing arguments to toolbar macros (Word 2002

    I'm having difficulty imagining when one would want to do this. It seems easier to have the procedure interrogate the environment (actioncontrol, document properties, etc.) than to code buttons to pass arguments. No?

  5. #5
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Passing arguments to toolbar macros (Word 2002

    The answer to your question is yes, if there's no simple, straightforward way to have the button's OnAction call the procedure with the appropriate arguments -- which I was hoping there was. The called procedure is (or would have been, anyway) one that gets called several different ways, not just from the toolbar button, and it wouldn't be interrogating the ActionControl property in cases where it wasn't called by the toolbar button.

    I think I'm warming up to the approach where there's a single macro that gets called by every button on a particular toolbar, which macro checks the Caption property of the ActionControl and calls the corresponding procedure (feeding it whatever arguments are appropriate). This involves some unnecessary lines of code for called procedures that don't need arguments and could just be called directly by the OnAction property, but that's probably compensated for by the organizational advantages of having the single macro that routes the clicks for all the buttons on the toolbar (and effectively "documents" the toolbar for easy reference).

Posting Permissions

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