Button shortcut keys with parameters!


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??


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
BoiledOnionAuthor Commented:
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.
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.