Here's a simple question from a complete neophyte

A

Alan Schmidt

I'm wanting a simple applescript to close a spreadsheet window and I want to
close the window without saving changes or being prompted to save changes. I
used the Script Editor to record the script and then tried to modify it to
do what I want but without success- it still prompts me to save when the
window gets closed. Can anyone help me out here- I'm at a complete loss with
AppleScript? Thanks!!! The script I've got is below:

tell application "Microsoft Excel"
Activate
Select Range "R1:R65536"
CopyObject Sheet "Accounts.txt"
Activate Window "Accounts.txt"
Close ActiveWindow saving No
end tell

BTW, this is OS 10.3 with Excel X.

Thanks again!

-Alan
 
B

Barry N. Wainwright

I'm wanting a simple applescript to close a spreadsheet window and I want to
close the window without saving changes or being prompted to save changes. I
used the Script Editor to record the script and then tried to modify it to
do what I want but without success- it still prompts me to save when the
window gets closed. Can anyone help me out here- I'm at a complete loss with
AppleScript? Thanks!!! The script I've got is below:

tell application "Microsoft Excel"
Activate
Select Range "R1:R65536"
CopyObject Sheet "Accounts.txt"
Activate Window "Accounts.txt"
Close ActiveWindow saving No
end tell

BTW, this is OS 10.3 with Excel X.

Thanks again!

-Alan

In the simplest form:

Tell app "Microsoft Excel" to close window 1 saving no

This will close the frontmost window, whatever it is.

Or, did you want to close a specific window?

--
Barry Wainwright
Microsoft MVP (see http://mvp.support.microsoft.com for details)
Seen the Entourage FAQ pages? - Check them out:
<http://www.entourage.mvps.org/toc.html>

Please post responses to this newsgroup. If I ask you to contact me
off-list, remove '.INVALID' from email address before replying.
 
A

Alan Schmidt

In the simplest form:

Tell app "Microsoft Excel" to close window 1 saving no

This will close the frontmost window, whatever it is.

Or, did you want to close a specific window?

Yes, a specific window.

I've tracked down my problem but I don't understand it or how to resolve it.
My current script looks like:

tell application "Microsoft Excel"
set ScreenUpdating to false
OpenText "Test"
set ScreenUpdating to true
Close Window "Test"
end tell

It works great, no prompt about saving when the window is closed. When I
insert the line to copy the active sheet (CopyObject Sheet "Test", inserted
after OpenText) then it prompts me if the file should be saved when closing-
even if I use "Close Window "Test" saving No". Crazy!

Okay- that seems weird to me but what's even weirder is that this only
happens on some text files- others that I have tested with work fine. Any
ideas??? Thanks!
--
Alan Schmidt
Bottom Line Software, Inc.
PO Box 20997, Bakersfield CA 93390-0997
phone 661-634-0600 fax 661-634-0688
email (e-mail address removed)
web www.goconnected.com
 
A

Alan Schmidt

Now I've found the source of this... It's the number of rows in the file.
Files with a small number of rows (my test file has about 125 but I don't
know what the threshold is) will close without prompting for the save. Files
with a larger number of rows (my test file has about 1300) will not close
without prompting for the save. Is this a bug or maybe a large clipboard???
Anyone have ideas for a work around?

Is there a more specific newsgroup I should be posting this to?
--
Alan Schmidt
Bottom Line Software, Inc.
PO Box 20997, Bakersfield CA 93390-0997
phone 661-634-0600 fax 661-634-0688
email (e-mail address removed)
web www.goconnected.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top