How to stop prompt to save changes to add-in



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.

Option Explicit
Public WithEvents appWord As Word.Application

Private Sub AssignNumpadPeriodToComma()

If FindKey(BuildKeyCode(wdKeyNumericDecimal)).KeyCategory = -1
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCategory:=wdKeyCategoryMacro, _
KeyCode:=BuildKeyCode(wdKeyNumericDecimal), _
CommandBars("Helpers").Controls(1).State = msoButtonDown
If FindKey(BuildKeyCode(wdKeyNumericDecimal)).KeyCategory = 2
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?", _

If intResponse = vbNo Then Cancel = True
End Sub


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