Dialog 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!
 
J

Jonathan West

Greg Maxey said:
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

Not all dialogs have a Word constant for them. I think this one doesn't.
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.

Don't bother with why, just trap the error.
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 you need to do is intercept the appropriate built-in commands, just as
you are doing for FileSave and FileSaveAs.

When you have 2 or more documents open, clicking the red X button in the top
right runs the DocClose command. You can intercept that just like you do
with FileSaveAs.

If you have just one document open, there are two X buttons in the top
right, and they do different things. The white X on a red background
triggers the FileExit command, the black X immediately below triggers
DocClose.

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!

I would recommend you forget about dialog 98, and intercept the built-in
commands instead.
 
G

Greg Maxey

Jonathan,

Thanks for the reply. I believe that you know what you are talking about, I
just am not catching on.

Here is two simple macros:

Public Sub FileExit()
MsgBox "Test"
WordBasic.FileExit
End Sub
Public Sub DocClose()
MsgBox "Test"
WordBasic.DocClose
End Sub

Where do they need to be in order to fire? I put them in a module in my
Normal.Dot and when I click either button, the promt to save the file pops
up, but I never get the message box indicating that I have intercepted the
command.

I know that I have another post on this topic (and error), but if you read
it then you know that I am trying to put a bookmark at the IP whenever a
user saves a document.

It seems that FileExit and DocClose will fire whenever the user clicks that
"X.." That in turn displays Dialogs(98). In order to keep from inserting
that bookmark if the user then doesn't save the file or cancels out of the
dialog it seems like I must find out what button they choose.

Thanks again.
 
J

Jonathan West

Greg Maxey said:
Jonathan,

Thanks for the reply. I believe that you know what you are talking about,
I just am not catching on.

Here is two simple macros:

Public Sub FileExit()
MsgBox "Test"
WordBasic.FileExit
End Sub
Public Sub DocClose()
MsgBox "Test"
WordBasic.DocClose
End Sub

Where do they need to be in order to fire? I put them in a module in my
Normal.Dot and when I click either button, the promt to save the file pops
up, but I never get the message box indicating that I have intercepted the
command.

Works for me. Did you save Normal.dot before trying to click the buttons?

For DocClose, the dialog of course will only appear if the Saved property of
the ActiveDocument is False. For FileExit, the dialog will appear for each
open document whose Saved property is False.
I know that I have another post on this topic (and error), but if you read
it then you know that I am trying to put a bookmark at the IP whenever a
user saves a document.

It seems that FileExit and DocClose will fire whenever the user clicks
that "X.." That in turn displays Dialogs(98). In order to keep from
inserting that bookmark if the user then doesn't save the file or cancels
out of the dialog it seems like I must find out what button they choose.

Not at all. The dialog is a simple Yes/No/Cancel message box. Make your own
instead using the MsgBox function, and get the return result in the normal
way. Then act according to the button clicked.
 
J

Jonathan West

By the way Greg, I think that Dialogs(98) is actually associated with
FileExit rather than DocClose.
 
G

Greg Maxey

Jonathan,

I am using Word2007 which may explain some of the differences.

I am making some progress but still not there.

Clicking "Close" on the Office Menu or the "X" (it's not Red anymore) is
not intercepted by either of these procedures:

Sub FileExit()
MsgBox "Test"
WordBasic.FileExit
End Sub

Sub DocClose()
MsgBox "Test"
WordBasic.DocClose
End Sub

I have found that the following will intercept the Office Menu "Close"
command:

Sub FileClose()
If Not ActiveDocument.Saved Then
Select Case MsgBox("Do you want to save the changes to " _
& Chr(34) + ActiveDocument.Name + Chr(34) & "?", _
vbExclamation + vbYesNoCancel, "Microsoft Office Word")
Case vbYes
FileSave
Case vbNo
ActiveDocument.Close wdDoNotSaveChanges
Case vbCancel
'Do Nothing
End Select
Else
ActiveDocument.Close wdDoNotSaveChanges
End If
End Sub

If only one document is open and you click the "X" one of these things
happen:
a. If the file is saved then it closes
b. If is not saved you are prompted to save.
c. If you click yes, the file is saved and closed, the application quits
d. If you click no, the file is not saved but closes, the application
quits
e. If you click "Cancel" or the "X"on the prompt then prompt closes and
nothing else happens

If more than one document is open on theses things happen:
a. If the file is saved then it closes and one of the other open
documents appears in its place
b. If is not saved you are prompted to save.
c. If you click yes, the file is saved but closes, one of the other open
documents appears in its place
d. If you click no, the file is not saved but closes, one of the other
open documents appears in its place
e. If you click "Cancel" or the "X"on the prompt then prompt closes and
nothing else happens

I looked through all of the Word Commands and the FileCloseOrExit seems like
the logical choice. The decription says "Closes the current document, if
only one document is open, exits from word.

I tried this code but it is not intercepting the user action of clicking on
"X"

Sub FileCloseOrExit()
If Not ActiveDocument.Saved Then
Select Case MsgBox("Do you want to save the changes to " _
& Chr(34) + ActiveDocument.Name + Chr(34) & "?", _
vbExclamation + vbYesNoCancel, "Microsoft Office Word")
Case vbYes
FileSave
Case vbNo
ActiveDocument.Close wdDoNotSaveChanges
Case vbCancel
'Do Nothing
End Select
Else
ActiveDocument.Close wdDoNotSaveChanges
End If
If Documents.Count = 0 Then Application.Quit
End Sub

Once again I am in over my head :-(. Any other ideas?
 
K

Klaus Linke

Sub DocClose()
MsgBox "Test"
WordBasic.DocClose
End Sub

Strange... that does intercept the "X" in Word 2003. If it doesn't in 2007, I'd report that as a bug.

Word2003 is a bit weird too. Word does falsely report "FileExit" for that button.

Regards,
Klaus
 

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