Dialog Index 98

G

Greg Maxey

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!
 
R

Russ

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.
 
K

Klaus Linke

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
 
G

Greg Maxey

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???
 
K

Klaus Linke

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
 
G

Greg Maxey

Klaus,

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

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

Top