Capture Save command, problem with capturing shortcut

Add-in Express™ Support Service
That's what is more important than anything else

Capture Save command, problem with capturing shortcut
 
Ole Andreas Ringdal


Guest


Hullo, everyone.

In Word, I have made a custom form to be shown/acted upon before the FileSave command occurs. I have successfully captured the click of the Save button on the Standard toolbar, as well as selecting Save from the File menu. I also intend to catch the Ctrl+S keyboard shortcut, of course.

The following is the code that I have for each of the three instances of invoking the Save command:


        Dim dlgSave As frmSave = Nothing

        Try
            dlgSave = New frmSave
            If dlgSave.ShowDialog() = DialogResult.OK Then
                myDocument = WordApp().ActiveDocument
                If myDocument.Path = "" Then
                    WordApp.Dialogs(Word.WdWordDialog.wdDialogFileSaveAs).Show()
                Else
                    myDocument.Save()
                End If
            End If
        Finally
            Dialog.Dispose()
        End Try


For both clicking the Save button on the Standard toolbar and selecting the Save command from the File menu, the form is displayed, and when I click the "OK"-button in that form, the normal Word FileSave or FileSaveAs dialogs are displayed. When I capture the Ctrl+S shortcut, the custom form is displayed, but when I click the "OK"-button, the form closes and nothing happens. No FileSave or FileSaveAs dialog, nothing.

I have read the http://www.add-in-express.com/forum/read.php?FID=5&TID=1099&MID=5354&phrase_id=253101 thread, but it doesn't provide an example. Sergey says there that
The default action doesn't work if you override it via ADXKeyboardShortcut component. In fact it is not possible to control the default behaviour of Outlook. You can only disable the standard action and then implement it in the add-in code using the Outlook Object Model.


Does this also apply to Word? And if so, and what he says is true for Word as well, how does one "disable the standard action and then implement it in add-in code using the Word Object Model"?

Anyone else struggled with this? Any help would be greatly appreciated.

Best regards,
Ole Andreas
Posted 01 Sep, 2006 02:09:16 Top
Ole Andreas Ringdal


Guest


(Update)

In addition to trying to capture Ctrl+S with a keyboard shortcut, I have now also unsuccessfully tried adding a button to the File menu instead:

ID = 3
DisableStandardAction = False
ShortcutText = Ctrl+S
Visible = False

Same result: My custom form is displayed when Ctrl+S is pressed, but when I click "OK" in the form, it closes and no FileSave or FileSaveAs dialog is shown. As is intended.
Posted 01 Sep, 2006 02:33:59 Top
Ole Andreas Ringdal


Guest


(Solved)

My bad, I'm embarrassed. I forgot to set the DialogResult to "OK" for the OK button in my form.

Now the custom dialog is displayed as it should, namely when I click the Save button on the toolbar, when I select the Save command from the File menu, and when I press Ctrl+S.

I am happy.
Posted 01 Sep, 2006 02:51:55 Top