PDA

View Full Version : Solved: Problem with Key Bindings



ABrown
09-01-2008, 05:59 AM
I have a template that contains the following code which runs on AutoOpen:
'Sub indent()
' Selection.Range.ListFormat.ListIndent
'End Sub
'Sub decrease()
' Selection.Range.ListFormat.ListOutdent
'End Sub
'
'Sub AssignTabKey()
'
'KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyTab), KeyCategory:= _
'wdKeyCategoryMacro, Command:="indent"
'End Sub
'
'Sub AssignShiftTabKey()
'KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyShift, wdKeyTab), KeyCategory:= _
'wdKeyCategoryMacro, Command:="decrease"
'End Sub

This is too assign the indent key and decrease indent key to the tab and shift and tab. This is because the template has all built in tabs removed for formatting purposes (we have to remove them as we have our schedule headings centered but need them indented in the TOC so have to have a tab applied after in the numbering setup).

The problem is - when I use normal - which doesn't contain this code on AutoOpen the tab key does not work - only by using control and tab.

I thought that the code for the template would not affect the Normal.dot template if it wasn't contained in it, but I am obviously not getting something with regard to key bindings. Can I set the keybinding for the tab key back to the tab key when I open Normal?

Thanks for any help - really stuck on this....

Annette

TonyJollans
09-01-2008, 06:57 AM
Hi Annette,

Key Bindings will apply to whatever the CustomizationContext is set to at the time and the default is the Normal Template, so, before doing them you need to set it; how best depends on where the code is but this should work:


Sub AssignTabKey()
CustomizationContext = MacroContainer
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyTab), KeyCategory:= _
wdKeyCategoryMacro, Command:="indent"
End Sub

Sub AssignShiftTabKey()
CustomizationContext = MacroContainer
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyShift, wdKeyTab), KeyCategory:= _
wdKeyCategoryMacro, Command:="decrease"
End Sub


You shouldn't actually need to do it on Open - once done it should be saved in the template.

TonyJollans
09-01-2008, 07:03 AM
Incidentally, you shouldn't need your own procedures for the indenting/outdenting. You should be able to assign keys to the Word commands:

CustomizationContext = MacroContainer
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyTab), KeyCategory:= _
wdKeyCategoryCommand, Command:="ListIndent"

ABrown
09-01-2008, 08:19 AM
Thanks Tony - a great help (again!). This is exactly what I needed.....

Annette:clap: