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