rdb1968
October 12, 2015, 4:28pm
#1
Hi all
Maybe I am to stupid to see it but why is this line working
tell application “Microsoft Excel” to open POSIX file “/Users/RDB/Desktop/ron.xlsx”
And this not
set filepath to “/Users/RDB/Desktop/ron.xlsx” as string
tell application “Microsoft Excel” to open POSIX file filepath
Thanks
StefanK
October 12, 2015, 4:47pm
#2
Hi,
you’re not stupid, the reason is that AppleScript treats POSIX file differently if the argument is a literal string or a variable.
For more details please read : https://www.safaribooksonline.com/library/view/applescript-the-definitive/0596102119/ch13s09s02.html
rdb1968
October 12, 2015, 6:13pm
#3
Hi Stefan
Thanks for your reply
If I understand it correct, I make it this now and this is working.
set filepath to (POSIX path of file “/Users/rondebruin/Desktop/TestFolder2/zz1.xlsx”)
tell application “Microsoft Excel” to open file filepath
Am I correct ?
StefanK
October 12, 2015, 6:21pm
#4
Too complicated, Excel accepts simple POSIX paths
set filepath to "/Users/rondebruin/Desktop/TestFolder2/zz1.xlsx"
tell application "Microsoft Excel" to open filepath
PS: please use the AppleScript tags when you’re posting code
rdb1968
October 12, 2015, 6:24pm
#5
Hi Stefan
I must use file in the script.
Reason is to avoid the grant access dialog in Office 2016
StefanK
October 12, 2015, 6:27pm
#6
Then use alias which is also bridged to NSURL like file
set filepath to (POSIX file "/Users/rondebruin/Desktop/TestFolder2/zz1.xlsx") as alias
tell application "Microsoft Excel" to open filepath
rdb1968
October 12, 2015, 6:33pm
#7
Thanks for this Stefan, working correct, do you have a suggestion for saving a file in Excel and to avoid the grant access dialog. When you open a file you need File or Alias instead of only open to avoid that stupid dialog.
Really looking for some script that can fix this for saving a file also.
StefanK
October 12, 2015, 6:46pm
#8
I don’t have Office 2016, please try
set filePath to "HD:path:to:file.xlsx"
set fileURL to filePath as «class furl»
this syntax creates explicit a file URL which is treated the same way as file and alias
rdb1968
October 12, 2015, 6:57pm
#9
No got the grant access dialog for the desktop with this tester
set destinationPath to (path to desktop as text) & "workbookName.xlsx"
set fileURL to destinationPath as «class furl»
tell application "Microsoft Excel"
save active workbook in fileURL
end tell
I hope you have a other suggestion that I can try