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 98 by Jonathan

Jonathan
Fri Nov 23 05:21:10 PST 2007


"Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
news:OSN5UaNLIHA.5860@TK2MSFTNGP04.phx.gbl...
> 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.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup



Re: Dialog 98 by Greg

Greg
Fri Nov 23 06:03:46 PST 2007

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.

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


Jonathan West wrote:
> "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
> news:OSN5UaNLIHA.5860@TK2MSFTNGP04.phx.gbl...
>> 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.



Re: Dialog 98 by Jonathan

Jonathan
Fri Nov 23 06:56:16 PST 2007


"Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
news:eUQEpmdLIHA.4752@TK2MSFTNGP05.phx.gbl...
> 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.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup



Re: Dialog 98 by Jonathan

Jonathan
Fri Nov 23 09:32:07 PST 2007

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


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup



Re: Dialog 98 by Greg

Greg
Fri Nov 23 12:28:24 PST 2007

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?

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

"Jonathan West" <jwest@mvps.org> wrote in message
news:e1x9DEeLIHA.3852@TK2MSFTNGP06.phx.gbl...
>
> "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
> news:eUQEpmdLIHA.4752@TK2MSFTNGP05.phx.gbl...
>> 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.
>
>
> --
> Regards
> Jonathan West - Word MVP
> www.intelligentdocuments.co.uk
> Please reply to the newsgroup
>
>



Re: Dialog 98 by Klaus

Klaus
Sat Nov 24 10:35:13 PST 2007

> 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