• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: more Excel script woes - paths
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: more Excel script woes - paths


  • Subject: Re: more Excel script woes - paths
  • From: Craig Sutherland <email@hidden>
  • Date: Thu, 11 Oct 2007 10:41:58 -0500

On Oct 11, 2007, at 8:31 AM, David Cake wrote:

All I really want to do is (in the middle of a script that does a bunch of things)
tell application "Microsoft Excel"
save workbook as filename "myfile.xls"
end tell
but that gets me is the Applescript error "Microsoft Excel got an error: Can't continue save workbook as."
>snip<
Check the Applescript Dictionary for Excel to see the syntax for the Save command in the Standard Suite. You'll see- save object [in Macintosh path] [as add in/CSV/and many other file types]. The square brackets indicate optional parameters. At times Applescript is so similar to English that new scripters fall into the trap of thinking that a logical English (Oxymoron?) expression rather than the correct Applesscript syntax will work. If you want the file saved to the Desktop:
--
set desktopPath to (path to desktop as string) --default type is alias and a string is needed for concatenation


tell application "Microsoft Excel"
	save active workbook in (desktopPath & "myfile.xls")
end tell
--
Now, I suspect this might be something to do with not supplying a full path to my file, and Excel being confused as to what is the current folder (or at least, Excels idea not being the same as mine), because I have no idea how to set the current folder.

OMM Excel saves files to my Home folder unless the script specifies a different location.


I've already opened files in the current folder etc, but its just a guess that this will lead Excel to the light.

If you want to use the path to a file previously opened, you can get the path to that workbook as it is opened and save that to a variable. The idea being to later use that in specifying the path for saving other workbooks.
--
set homefolderPath to path to (home folder as string)


tell application "Microsoft Excel"
open homefolderPath & "Documents:myWorkbook1.xls"
set workbookPath to (path of active workbook & ":") --Excel does not put the needed delimiter on the path returned


make new workbook --adding a workbook
save active workbook in (workbookPath & "myNewWorkbook.xls")-- save in same folder as first workbook
end tell
--
But this just, so far, leads me into other frustration, with Finder scripting, as I don't know how to get my working folder into a useful text path. I want to do something like
tell application "Finder"
set currentfolder to "filename" of desktop
set folderpath to path to currentfolder as string
end tell
save workbook as folderpath & "myfile.xls"
Some parts of the examples included can shed some light on this. There are a number of Finder scripts included with the OS located in / Library/Scripts/Finder/. Take a look through these. Make copies into your domain and fiddle with them while the Finder Dictionary is open. Access the dictionaries through Script Editor -> File -> Open Dictionary… Also look at the Standard Additions Dictionary.
David
Craig

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >more Excel script woes - paths (From: David Cake <email@hidden>)

  • Prev by Date: Re: Address Book custom fields?
  • Next by Date: Re: Address Book custom fields?
  • Previous by thread: more Excel script woes - paths
  • Next by thread: display alert giving up after
  • Index(es):
    • Date
    • Thread