M
mmalinsky
I have an add-in with a toolbar button. The macro remaps the numpad
decimal to a comma. I have code in the macro to give the button a
state of msoButtonDown when the remapping is in effect and msoButtonUp
when the remapping is not in effect. When I open a Word document, the
state is msoButtonUp. If I change the state of the button, Word
prompts me to save changes to the add-in. If I say yes, the state of
the button is saved.
What I'm trying to do is that when I exit Word, I would like the make
sure the button state is msoButtonUp and that the remapping is
cancelled. I have tried to do this using the DocumentBeforeClose
event, but it doesn't seem to be working, unless I'm implementing it
improperly. The code is below.
Any help is appreciated.
Thanks.
--------------
Option Explicit
Public WithEvents appWord As Word.Application
Private Sub AssignNumpadPeriodToComma()
If FindKey(BuildKeyCode(wdKeyNumericDecimal)).KeyCategory = -1
Then
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCategory:=wdKeyCategoryMacro, _
KeyCode:=BuildKeyCode(wdKeyNumericDecimal), _
Command:="TypeAComma"
CommandBars("Helpers").Controls(1).State = msoButtonDown
Else
If FindKey(BuildKeyCode(wdKeyNumericDecimal)).KeyCategory = 2
Then
FindKey(BuildKeyCode(wdKeyNumericDecimal)).Clear
CommandBars("Helpers").Controls(1).State = msoButtonUp
End If
End If
End Sub
Sub TypeAComma()
Selection.TypeText ","
End Sub
Private Sub appWord_DocumentBeforeClose _
(ByVal Doc As Document, _
Cancel As Boolean)
Dim intResponse As Integer
intResponse = MsgBox("Do you really " _
& "want to close the document?", _
vbYesNo)
If intResponse = vbNo Then Cancel = True
End Sub
decimal to a comma. I have code in the macro to give the button a
state of msoButtonDown when the remapping is in effect and msoButtonUp
when the remapping is not in effect. When I open a Word document, the
state is msoButtonUp. If I change the state of the button, Word
prompts me to save changes to the add-in. If I say yes, the state of
the button is saved.
What I'm trying to do is that when I exit Word, I would like the make
sure the button state is msoButtonUp and that the remapping is
cancelled. I have tried to do this using the DocumentBeforeClose
event, but it doesn't seem to be working, unless I'm implementing it
improperly. The code is below.
Any help is appreciated.
Thanks.
--------------
Option Explicit
Public WithEvents appWord As Word.Application
Private Sub AssignNumpadPeriodToComma()
If FindKey(BuildKeyCode(wdKeyNumericDecimal)).KeyCategory = -1
Then
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCategory:=wdKeyCategoryMacro, _
KeyCode:=BuildKeyCode(wdKeyNumericDecimal), _
Command:="TypeAComma"
CommandBars("Helpers").Controls(1).State = msoButtonDown
Else
If FindKey(BuildKeyCode(wdKeyNumericDecimal)).KeyCategory = 2
Then
FindKey(BuildKeyCode(wdKeyNumericDecimal)).Clear
CommandBars("Helpers").Controls(1).State = msoButtonUp
End If
End If
End Sub
Sub TypeAComma()
Selection.TypeText ","
End Sub
Private Sub appWord_DocumentBeforeClose _
(ByVal Doc As Document, _
Cancel As Boolean)
Dim intResponse As Integer
intResponse = MsgBox("Do you really " _
& "want to close the document?", _
vbYesNo)
If intResponse = vbNo Then Cancel = True
End Sub