Can't open text file with Applescript

T

tdi

Version: 2008
Operating System: Mac OS X 10.5 (Leopard)
Processor: Intel

I'm very frustrated trying to get Excel to open a .csv file. I get the not-so-helpful error:
"Microsoft Excel got an error: Can't continue open text file."

Here's my code:
on run {}
set Filepath to (choose file with prompt "Select file to convert for analysis:")
tell application "Microsoft Excel"
activate
open text file filename Filepath origin MSWindows data type delimited start row 8 field info {{1, 9}, {1, 1}} with comma without space, tab and other char
end tell
end run

It doesn't work even with all of the options off. In fact, I can't make the function work with any kind of text file. Can anyone please help?
 
T

tdi

I managed to figure out the issue, which is that 'open text file' takes /text/ as the filename, and 'choose file with prompt' returns an alias to the file. The working script now looks like this:
on run {}
set falias to (choose file with prompt "Select file to convert for analysis:" without invisibles)
tell application "Microsoft Excel"
activate
open text file filename (falias as text) origin MSDos data type delimited start row 8 field info {{1, 9}, {1, 1}} with comma without space, tab and other char
end tell
end run
 

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