Closing Microsoft Word

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
S1013
Newbie
Posts: 5
Joined: Thu Nov 14, 2002 8:03 pm

Closing Microsoft Word

Post by S1013 » Mon Nov 18, 2002 10:25 pm

:?:
Have a mail merge macro that after it prints, I would like to close the document & Microsoft Word. However, when Word closes, I get the window: Do you want to save the changes you made to the document? Yes, No or Cancel. Anyone know how to automatically answer this?

Ernest

Post by Ernest » Tue Nov 19, 2002 10:23 pm

Hi,
try to detect the window title (could be different from the one you see)

Code: Select all

GetActiveWindow>window_title,X,Y
then

Code: Select all

MouseOver>window_title*,OK
LClick
or

Code: Select all

WaitWindowOpen>window_title
// repeat till you've reached the button to click on
Press Tab 
Press Enter
or

Code: Select all

FindWindowWithText>Do you want to save the changes you made to the document?, setfocus_flag,result_variable,check_edits_flag
// repeat till you've reached the button to click on
Press Tab
Press Enter
Check command reference for details.

Rgds,
Ernest





[/code]

User avatar
Marcus Tettmar
Site Admin
Posts: 7394
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Nov 20, 2002 2:59 pm

Hi,

I have found that the following closes Microsoft Word without causing any prompts at all. I don't think it *should*, but it does!

CloseWindow>Microsoft Word*

Or, using the new WaitWindowChanged function, you can do this:

SetFocus>Microsoft Word*
Press ALT
Press F4
Release ALT
WaitWindowChanged>0
IfWindowOpen>Microsoft Word,cancelbox
Goto>cancelled
Label>cancelbox
Send>N
Label>cancelled

What this does is initiate the close sequence by sending ALT-F4 and then waits until the active window changes. It then checks to see if the new active window is the "Microsoft Word" dialog box. If so, it sends 'N' to press the 'No' button. Done.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts