Huh, oddly enough, your first script works for me. for some reason (and this is wrong) Excel is accepting the path as string but not as an alias. If the first script you posted doesn’t work, then most likely, the file isn’t in your Documents folder or its name is not what you think it is.
I copied and pasted the file path into the excel chooser and it opened fine. That eliminates any possibility of my eyes missing a typo in the file name. So the file exists but I still get that dumb error. I also tried several other excel files and they all do the same thing. I think I’ll try opening Word instead to see if that works. That may tell me if it is a problem with Office or just Excel.
Isn’t this interesting. Not only does Word work but it can even open the suspect file. Just change ‘Excel’ to ‘Word’ in your script and bingo! That must mean there is a problem with Excel but what could it be.
Sorry guy’s But your code doesn’t work on my 10.4.7 system with Office 2004 and AppleScript 1.10.6.
I don’t know what really go wrong but I don’t get an error. I’m trying to op an csv file but nothing happens.
I made an solution, not an regular way to open an file for an application but it works, and that’s what we’re looking for aren’t we?
Only problem here is that the open command doesn’t wait till the document is fully opened but returns directly. So the script is going further while the document isn’t open. that’s why I put the repeat in this function to get the name of document 1. As long the document isn’t fully opened then excel will return missing value. WIth the repeat we will know when document 1 is fully opened and continue the script.
on openExcelFile(theFile)
tell application "Microsoft Excel"
activate
close every document without saving
end tell
do shell script "open -a '/Applications/Microsoft Office 2004/Microsoft Excel' " & quoted form of theFile
set theDoc to missing value
repeat while theDoc is missing value
set theDoc to loadDocName()
delay 0.5
end repeat
return theDoc
end openExcelFile
on loadDocName()
tell application "Microsoft Excel"
set theDoc to name of document 1
end tell
end loadDocName