Applescript can't tell excel to open a workbook

Discussion in 'Mac Programming' started by hackthat, Feb 12, 2009.

  1. macrumors newbie

    #1
    I don't ask questions of forums without spending a great deal of time searching for answers first. But this one seems so easy yet it hasn't worked after hours of searching

    I wan excel to open a workbook. I have excel 2004 and OSX

    my code is

    tell application "Microsoft Excel" to open workbook workbook file name "HD:User:intern:Desktop:learningAS:SL__FORECAST.xls" with read only

    the error I get is from excel saying
    "SL__FORECAST.xls" cannot be accessed the file may be read-only, or you may be trying to access a read only location. Or the server the document is stored on may not be responding. "

    I've tried it with "read only", and without. Tried it with different files that have been local and on a server. I've tried it with excel open and closed. I've tried changing the permissions on the file to be world read-writeable. I've tried all kinds of different syntax modifications among them:

    tell application "Microsoft Excel" to open "HD:User:intern:Desktop:learningAS:SL__FORECAST.xls

    I keep getting the same error. Does applescript run as some kind of funny user?

    thanks in advance,
    -matt

    "Applescript is so easy it's like writing in english" <-- ********
     
  2. macrumors 601

    HiRez

    #2
    Yeah, I have the same problem with Excel files. Dunno why it does that but there is definitely a problem there (my files are not password protected and they reside on my local drive, and the same thing happens even with a new, blank .xls or .xlsx doc).

    But, you can get around it like this, using the UNIX open command:

    Code:
    do shell script "open -a /Applications/Microsoft\\ Office\\ 2008/Microsoft\\ Excel.app ~/Desktop/test.xls"
    (Make sure this command is NOT inside your tell block to Excel). Obviously, adjust your paths for the application and file as necessary (or build the path as a string). This should open any doc just as if you double-clicked it in the Finder, and will open the Excel documents that AppleScript won't directly.
     

Share This Page