Button shortcut keys with parameters!

Posted on 2008-11-10
Last Modified: 2012-05-06

I am looking to set-up shortcut keys to custom buttons in Word. I can successfully do this by using keybindings.add() and calling the macro in the commandbarbutton.OnAction property. The problem I have is that the commandbarbutton also has a Parameter set and I am unable to pass this to the macro through the keybindings.

In simple terms, what I need to do is somehow say "when shift + ctrl" are pressed execute this custom macro, passing this parameter to it". I need to do this for several buttons with several different shortcut keys.

Does anybody know how I can do this? Or at least some pointers??


Question by:BoiledOnion
    LVL 76

    Expert Comment

    I may not understand the problem properly, but I would expect the procedure that the OnAction calls to already have a way of finding the Parameter value if it was needed.

    Author Comment

    Hi Graham,

    You are correct - I retrieve the "parameter" by looking at "ActiveDocument.CommandBars.ActionControl.Parameter", which works fine when the button is clicked, but not when the shortcut key to the macro is pressed as no button is involved at this point.
    LVL 76

    Accepted Solution

    Perhaps the answer to this question is similar to that of 'How to do I get to Tipperary?', Tha is 'Don't start from here'.

    I think you will need separate macros for the keystrokes and the OnAction Macro, each calling the main part of your original OnAction Macro

    Sub KeystrokeMacroForButton1()
        MainActionMacro 1
    End Sub
    Sub KeystrokeMacroForButton2()
        MainActionMacro 2
    End Sub
    Sub OnActionMacro()
        MainActionMacro ActiveControl.Parameter
    End Sub
    Sub MainActionMacro(MyParameter )
        Select case MyParameter
    End Sub

    Open in new window


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    My experience with Windows 10 over a one year period and suggestions for smooth operation
    Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
    Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now