KeyBinding for Alt+C and Alt+N

T

Tim

When I try to add keybindings to Alt+C and Alt+N, I get a Run-time
error '5346'.
"Word cannot change the function of the specified key."

Below is a sample of the lines of code.

CustomizationContext = ActiveDocument.AttachedTemplate
KeyBindings.Add KeyCategory:=wdKeyCategoryCommand,
Command:="ToolBarMenu.InsertCautionBP", _
KeyCode:=BuildKeyCode(arg1:=wdKeyAlt, arg2:=wdKeyC)

What is Alt+C & Alt+N suppose to do?
Is there a way around it?

Appreciate all Help.

Thanks,
 
J

Jean-Guy Marcil

Tim was telling us:
Tim nous racontait que :
When I try to add keybindings to Alt+C and Alt+N, I get a Run-time
error '5346'.
"Word cannot change the function of the specified key."

Below is a sample of the lines of code.

CustomizationContext = ActiveDocument.AttachedTemplate
KeyBindings.Add KeyCategory:=wdKeyCategoryCommand,
Command:="ToolBarMenu.InsertCautionBP", _
KeyCode:=BuildKeyCode(arg1:=wdKeyAlt, arg2:=wdKeyC)

What is Alt+C & Alt+N suppose to do?
Is there a way around it?

I think the problem lies with
"ToolBarMenu.InsertCautionBP"
Word cannot recognize this, hence it cannot create the bind the key
combination. Is ToolBarMenu the name of a module, a sub, a project...
IIRC, ALT+C and ALT+N are not assigned to anything, so it should not be a
problem to bind anything you want to them.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
T

Tim

Thanks, you are correct. The problem does lie within
"ToolBarMenu.InsertCautionBP". ToolBarMenu is a module and
InsertCautionBP is a procedure. The problem is that
this procedure is expecting a argument.

Thanks for the Help.

Tim
 
J

Jonathan West

Tim said:
Thanks, you are correct. The problem does lie within
"ToolBarMenu.InsertCautionBP". ToolBarMenu is a module and
InsertCautionBP is a procedure. The problem is that
this procedure is expecting a argument.

Thanks for the Help.

Hi Tim,

The OnAction property can only be set to a VBA routine which meets all the
following conditions

- A public Sub
- In a module (as opposed to a Class for UserForm)
- with no parameters

If you want to be able to pass a paramater to a from the button, it can be
done, but it is a bit convoluted.

Every Commandbutton has a Tag property. You can't set the Tag from within
the user interface, but you can in code. Suppose you have set the tag, you
can then do something like this

Dim strTag as Tag
If CommandBars.ActionControl Is Nothing Then
'not called from a button
MsgBox "the macro wasn't called by clicking a toolbar button"
Exit
Else
strTag = CommandBars.ActionControl.Tag
End If
'Now you can use the value of strTag in your macro
 
J

Jean-Guy Marcil

Jonathan West was telling us:
Jonathan West nous racontait que :
Hi Tim,

The OnAction property can only be set to a VBA routine which meets
all the following conditions

- A public Sub
- In a module (as opposed to a Class for UserForm)
- with no parameters

If you want to be able to pass a paramater to a from the button, it
can be done, but it is a bit convoluted.

Every Commandbutton has a Tag property. You can't set the Tag from
within the user interface, but you can in code. Suppose you have set
the tag, you can then do something like this

Dim strTag as Tag
If CommandBars.ActionControl Is Nothing Then
'not called from a button
MsgBox "the macro wasn't called by clicking a toolbar button"
Exit
Else
strTag = CommandBars.ActionControl.Tag
End If
'Now you can use the value of strTag in your macro

Sorry Jonathan, just to be sure I did not miss something here...
The OP was writing about KeyBinding to a macro... Aren't OnAction property
for commandbar controls?
How do you make the connection to a keyboard shortcut?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top