These Keybinding statements are to be executed whenever a document is
opened:


Public Sub AutoOpen()
CustomizationContext = ActiveDocument
KeyBindings.Add _
KeyCategory:=wdKeyCategoryMacro, _
Command:="Quote", _
KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyShift, wdKeyQ)
KeyBindings.Add _
KeyCategory:=wdKeyCategoryMacro, _
Command:="Comment", _
KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyShift, wdKeyC)
KeyBindings.Add _
KeyCategory:=wdKeyCategoryMacro, _
Command:="TrackChanges", _
KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyShift, wdKeyT)
End Sub

I installed this procedure in the "This Document" module of the document.

Unfortunately, the keys are not assigned when the document is opened. What's
wrong?

John Wirt

- - - - - - - - - - - - - - - - - -
The called procedures are:

Sub Quote()
Selection.Style = ActiveDocument.Styles("Quote")
End Sub
Sub Comment()
Selection.TypeText Text:=vbTab & "JW: "
End Sub

Sub TrackChanges()
If ActiveDocument.TrackRevisions = False Then
With ActiveDocument
.TrackRevisions = True
.ShowRevisions = True
End With
Else
With ActiveDocument
.TrackRevisions = False
.ShowRevisions = True
End With
End If
End Sub

Re: KeyBinding with AutoOpen by Jay

Jay
Sat Jul 30 21:35:37 CDT 2005


Hi John,

You can place AutoOpen in a regular module (use Insert > Module in the
VBA editor) or you can call it Document_Open and put it in the
ThisDocument module. Don't mix'n'match -- it doesn't work.

The differences between these types of procedures are explained at
http://word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

On Sat, 30 Jul 2005 21:07:26 -0400, "John Wirt" <jwirt@toward.com>
wrote:

>These Keybinding statements are to be executed whenever a document is
>opened:
>
>
>Public Sub AutoOpen()
> CustomizationContext = ActiveDocument
> KeyBindings.Add _
> KeyCategory:=wdKeyCategoryMacro, _
> Command:="Quote", _
> KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyShift, wdKeyQ)
> KeyBindings.Add _
> KeyCategory:=wdKeyCategoryMacro, _
> Command:="Comment", _
> KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyShift, wdKeyC)
> KeyBindings.Add _
> KeyCategory:=wdKeyCategoryMacro, _
> Command:="TrackChanges", _
> KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyShift, wdKeyT)
>End Sub
>
>I installed this procedure in the "This Document" module of the document.
>
>Unfortunately, the keys are not assigned when the document is opened. What's
>wrong?
>
>John Wirt
>
>- - - - - - - - - - - - - - - - - -
>The called procedures are:
>
>Sub Quote()
> Selection.Style = ActiveDocument.Styles("Quote")
>End Sub
>Sub Comment()
> Selection.TypeText Text:=vbTab & "JW: "
>End Sub
>
>Sub TrackChanges()
> If ActiveDocument.TrackRevisions = False Then
> With ActiveDocument
> .TrackRevisions = True
> .ShowRevisions = True
> End With
> Else
> With ActiveDocument
> .TrackRevisions = False
> .ShowRevisions = True
> End With
> End If
>End Sub
>