Word 2007

I don't know the constant name for the dialog that displays when you click
on the right hand "X" to close a document, but I can make it appear with:

Sub Testing()
Dialogs(98).Show
End Sub

What I can't figure out, is why it causes a RunTime Error 4198 "Command
Failed" if I click "Cancel" or the "X" in the dialog.

Second issue

I am trying to intercept the FileSave and FileSaveAs commands and perform an
action on save. I have that part figured out, but I need to sort out how to
make it work if the user clicks the "X" or the "Close" command on the Office
Menu. I have put code in the Document_Close Event and I only want a part of
it to execute if the user choose to Save the file and not execute if they
canceled out of the dialog, close the dialog with the "X" or select not to
save the file.

It seems like the Document_Close event is fired before that dialog appears.
I can't figure out how to determine what the User does in that dialog:

What doesn't work and I think I kno why is something like:

Private Sub Document_Close()
If Dialogs(98).Show = -1 Then
'Call a procedure"
Else
'Do nothing
End If
End Sub

Help, Help, Help!




--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Re: Dialog Index 98 by Russ

Russ
Wed Nov 21 16:45:45 PST 2007

Greg,
It appears that anything initiating user closing action, triggers
Document_Close, then the other dialog appears if document or if no
documents, global template, etc., needs saving.
I tried sending Escape key in Document_Close but it looks like the other
dialog doesn't appear until Document_Close exits.

Private Sub Document_Close()
If Not ActiveDocument.Saved Then
MsgBox "Not saved"
Selection.EscapeKey
Exit Sub
Else
MsgBox "Saved"
Selection.EscapeKey
Exit Sub
End If
End Sub

I think the errors come because it is already in a process that will or did
popup a dialog when a request is read to popup another.

> Word 2007
>
> I don't know the constant name for the dialog that displays when you click
> on the right hand "X" to close a document, but I can make it appear with:
>
> Sub Testing()
> Dialogs(98).Show
> End Sub
>
> What I can't figure out, is why it causes a RunTime Error 4198 "Command
> Failed" if I click "Cancel" or the "X" in the dialog.
>
> Second issue
>
> I am trying to intercept the FileSave and FileSaveAs commands and perform an
> action on save. I have that part figured out, but I need to sort out how to
> make it work if the user clicks the "X" or the "Close" command on the Office
> Menu. I have put code in the Document_Close Event and I only want a part of
> it to execute if the user choose to Save the file and not execute if they
> canceled out of the dialog, close the dialog with the "X" or select not to
> save the file.
>
> It seems like the Document_Close event is fired before that dialog appears.
> I can't figure out how to determine what the User does in that dialog:
>
> What doesn't work and I think I kno why is something like:
>
> Private Sub Document_Close()
> If Dialogs(98).Show = -1 Then
> 'Call a procedure"
> Else
> 'Do nothing
> End If
> End Sub
>
> Help, Help, Help!
>
>
>

--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID


Re: Dialog Index 98 by Klaus

Klaus
Thu Nov 22 04:53:10 PST 2007

> I don't know the constant name for the dialog that displays when=20
> you click on the right hand "X" to close a document,=20

FileExit

> but I can make it appear with:
>=20
> Sub Testing()
> Dialogs(98).Show
> End Sub
>=20
> What I can't figure out, is why it causes a RunTime Error 4198 =
"Command=20
> Failed" if I click "Cancel" or the "X" in the dialog.

You'd usually disable the Escape key before you show a dialog to avoid =
that error, and enable it later on:

Application.EnableCancelKey=3DFalse
' Show dialog...
Application.EnableCancelKey=3DTrue

Regards,
Klaus

Re: Dialog Index 98 by Greg

Greg
Thu Nov 22 05:43:10 PST 2007

Klaus,

Thanks for the reply:

Sub Test1()
Dialogs(98).Show
End Sub
Shows the dialog that asked a user if they want to save an open document if
they click the "X" button or the File Close command.

I would normally not use a number but a constant like:
Sub Test2()
Dialogs(wdDialogFileSaveAs).Show
End Sub

I can't find a constant for the value 98. Yes:

Sub Test3()
MsgBox Dialogs(98).CommandName
End Sub

Returns "FileExit:

But
Sub Test4()
Dialogs(wdDialogsFileExit).Show
End Sub

Doesn't compile

> You'd usually disable the Escape key before you show a dialog to avoid
> that error, and enable it later on

I don't want to disable the Escape key.

Here is what I am trying to do and why I need to know what the user does
when that dialog is displayed after the user presses the "X" or selects File
Close:

I have written a macro that inserts a bookmark at the selection when the use
saves a document. To fire this macro I have intercepted the FileSave,
FileSaveAll, and FileSaveAs events.

For example:
Sub FileSaveAs()
With Dialogs(wdDialogFileSaveAs)
If .Show = 0 Then Exit Sub
Selecting.QuickSaveMark 'This is a procedure in another module that sets
the bookmark
End With
End Sub

This works fine if the user has an new unsaved document and selects either
Save or SaveAs before Closing. However, if the user press Close or the "X"
then that dialog displays. If the user choses "Yes" then the FileSaveAs
command is executed. The above code doesn't intercept it so the file is
saved and the bookmark isn't inserted:

I am trying to figure out how to capture what the user does when Dialogs(98)
is displayed???



--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Klaus Linke wrote:
>> I don't know the constant name for the dialog that displays when
>> you click on the right hand "X" to close a document,
>
> FileExit
>
>> but I can make it appear with:
>>
>> Sub Testing()
>> Dialogs(98).Show
>> End Sub
>>
>> What I can't figure out, is why it causes a RunTime Error 4198
>> "Command Failed" if I click "Cancel" or the "X" in the dialog.
>
> You'd usually disable the Escape key before you show a dialog to
> avoid that error, and enable it later on:
>
> Application.EnableCancelKey=False
> ' Show dialog...
> Application.EnableCancelKey=True
>
> Regards,
> Klaus



Re: Dialog Index 98 by Klaus

Klaus
Thu Nov 22 08:25:48 PST 2007

There isn't a wdDialog constant for that dialog (and lots of other =
dialogs).
BTW, the control ID is 752, so =
CommandBars.FindControl(Id:=3D752).Execute would do the same as =
Dialogs(98).Execute. Not that that helps you any ;-)


> I don't want to disable the Escape key.
When a dialog is open, hitting the Escape key does the same as clicking =
on the close "X".
Setting EnableCancelKey to False just prevents the error 4198 if the =
user cancels out of the dialog.

But that doesn't seem to be your main problem anyway.

I've never seen a solution for intercepting when the user clicks the =
doc's close button. Usually, you'd simply write your own macro for the =
command (Sub FileExit() in this case), but that does not work (... at =
least in older versions).

Maybe you could put whatever you want to do in the Sub Document_Close() =
event handler?

Klaus


"Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote:
> Klaus,
>=20
> Thanks for the reply:
>=20
> Sub Test1()
> Dialogs(98).Show
> End Sub
> Shows the dialog that asked a user if they want to save an open =
document if=20
> they click the "X" button or the File Close command.
>=20
> I would normally not use a number but a constant like:
> Sub Test2()
> Dialogs(wdDialogFileSaveAs).Show
> End Sub
>=20
> I can't find a constant for the value 98. Yes:
>=20
> Sub Test3()
> MsgBox Dialogs(98).CommandName
> End Sub
>=20
> Returns "FileExit:
>=20
> But
> Sub Test4()
> Dialogs(wdDialogsFileExit).Show
> End Sub
>=20
> Doesn't compile
>=20
>> You'd usually disable the Escape key before you show a dialog to =
avoid=20
>> that error, and enable it later on
>=20
> I don't want to disable the Escape key.
>=20
> Here is what I am trying to do and why I need to know what the user =
does=20
> when that dialog is displayed after the user presses the "X" or =
selects File=20
> Close:
>=20
> I have written a macro that inserts a bookmark at the selection when =
the use=20
> saves a document. To fire this macro I have intercepted the FileSave, =

> FileSaveAll, and FileSaveAs events.
>=20
> For example:
> Sub FileSaveAs()
> With Dialogs(wdDialogFileSaveAs)
> If .Show =3D 0 Then Exit Sub
> Selecting.QuickSaveMark 'This is a procedure in another module that =
sets=20
> the bookmark
> End With
> End Sub
>=20
> This works fine if the user has an new unsaved document and selects =
either=20
> Save or SaveAs before Closing. However, if the user press Close or =
the "X"=20
> then that dialog displays. If the user choses "Yes" then the =
FileSaveAs=20
> command is executed. The above code doesn't intercept it so the file =
is=20
> saved and the bookmark isn't inserted:
>=20
> I am trying to figure out how to capture what the user does when =
Dialogs(98)=20
> is displayed???


Re: Dialog Index 98 by Greg

Greg
Thu Nov 22 09:29:28 PST 2007

Klaus,

That is one of the first things I tried. Problem is that event fires before
the Dialog appears.

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Klaus Linke wrote:
> There isn't a wdDialog constant for that dialog (and lots of other
> dialogs).
> BTW, the control ID is 752, so
> CommandBars.FindControl(Id:=752).Execute would do the same as
> Dialogs(98).Execute. Not that that helps you any ;-)
>
>
>> I don't want to disable the Escape key.
> When a dialog is open, hitting the Escape key does the same as
> clicking on the close "X".
> Setting EnableCancelKey to False just prevents the error 4198 if the
> user cancels out of the dialog.
>
> But that doesn't seem to be your main problem anyway.
>
> I've never seen a solution for intercepting when the user clicks the
> doc's close button. Usually, you'd simply write your own macro for
> the command (Sub FileExit() in this case), but that does not work
> (... at least in older versions).
>
> Maybe you could put whatever you want to do in the Sub
> Document_Close() event handler?
>
> Klaus
>
>
> "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote:
>> Klaus,
>>
>> Thanks for the reply:
>>
>> Sub Test1()
>> Dialogs(98).Show
>> End Sub
>> Shows the dialog that asked a user if they want to save an open
>> document if they click the "X" button or the File Close command.
>>
>> I would normally not use a number but a constant like:
>> Sub Test2()
>> Dialogs(wdDialogFileSaveAs).Show
>> End Sub
>>
>> I can't find a constant for the value 98. Yes:
>>
>> Sub Test3()
>> MsgBox Dialogs(98).CommandName
>> End Sub
>>
>> Returns "FileExit:
>>
>> But
>> Sub Test4()
>> Dialogs(wdDialogsFileExit).Show
>> End Sub
>>
>> Doesn't compile
>>
>>> You'd usually disable the Escape key before you show a dialog to
>>> avoid that error, and enable it later on
>>
>> I don't want to disable the Escape key.
>>
>> Here is what I am trying to do and why I need to know what the user
>> does when that dialog is displayed after the user presses the "X" or
>> selects File Close:
>>
>> I have written a macro that inserts a bookmark at the selection when
>> the use saves a document. To fire this macro I have intercepted the
>> FileSave, FileSaveAll, and FileSaveAs events.
>>
>> For example:
>> Sub FileSaveAs()
>> With Dialogs(wdDialogFileSaveAs)
>> If .Show = 0 Then Exit Sub
>> Selecting.QuickSaveMark 'This is a procedure in another module
>> that sets the bookmark
>> End With
>> End Sub
>>
>> This works fine if the user has an new unsaved document and selects
>> either Save or SaveAs before Closing. However, if the user press
>> Close or the "X" then that dialog displays. If the user choses
>> "Yes" then the FileSaveAs command is executed. The above code
>> doesn't intercept it so the file is saved and the bookmark isn't
>> inserted:
>>
>> I am trying to figure out how to capture what the user does when
>> Dialogs(98) is displayed???