
Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
> Word 2007
>
[quoted text clipped - 4 lines]
> 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
>
[quoted text clipped - 13 lines]
> 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:
>
[quoted text clipped - 7 lines]
>
> Help, Help, Help!
I would recommend you forget about dialog 98, and intercept the built-in
commands instead.

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Greg Maxey - 23 Nov 2007 14:03 GMT
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.

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
>> Word 2007
>>
[quoted text clipped - 57 lines]
> I would recommend you forget about dialog 98, and intercept the
> built-in commands instead.
Jonathan West - 23 Nov 2007 14:56 GMT
> Jonathan,
>
[quoted text clipped - 16 lines]
> 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
[quoted text clipped - 4 lines]
> 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.

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Jonathan West - 23 Nov 2007 17:32 GMT
By the way Greg, I think that Dialogs(98) is actually associated with
FileExit rather than DocClose.

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Greg Maxey - 23 Nov 2007 20:28 GMT
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?

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
>> Jonathan,
>>
[quoted text clipped - 35 lines]
> own instead using the MsgBox function, and get the return result in the
> normal way. Then act according to the button clicked.
Klaus Linke - 24 Nov 2007 18:35 GMT
> 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