Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Button shortcut keys with parameters!

Posted on 2008-11-10
Medium Priority
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
  • 2
LVL 77

Expert Comment

ID: 22923234
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

ID: 22923899
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 77

Accepted Solution

GrahamSkan earned 750 total points
ID: 22924794
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

580 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