Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Dialog Index 98

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Maxey - 21 Nov 2007 22:06 GMT
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!

Signature

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

Russ - 22 Nov 2007 00:45 GMT
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.

> Word 2007
>
[quoted text clipped - 32 lines]
>
> Help, Help, Help!

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Klaus Linke - 22 Nov 2007 12:53 GMT
> 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:
>
[quoted text clipped - 4 lines]
> 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
Greg Maxey - 22 Nov 2007 13:43 GMT
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???

Signature

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

>> I don't know the constant name for the dialog that displays when
>> you click on the right hand "X" to close a document,
[quoted text clipped - 19 lines]
> Regards,
> Klaus
Klaus Linke - 22 Nov 2007 16:25 GMT
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

> Klaus,
>
[quoted text clipped - 56 lines]
> I am trying to figure out how to capture what the user does when Dialogs(98)
> is displayed???
Greg Maxey - 22 Nov 2007 17:29 GMT
Klaus,

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

Signature

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

> There isn't a wdDialog constant for that dialog (and lots of other
> dialogs).
[quoted text clipped - 81 lines]
>> I am trying to figure out how to capture what the user does when
>> Dialogs(98) is displayed???

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.