How to get Excel to open tab delimited text file?

The following opens the file, but gives me a dialog box first.

set this_file to (((path to desktop folder) as text) & "filename.txt")
tell application "Microsoft Excel"
	launch
	activate
	open this_file
end tell

I want something like “open this_file with tab delimiters” but I can’t figure out what the proper syntax is.

I’ve been doing a project here for a couple of days that had to end with a similar thing: open a created tab delimited text file in excel and save it as an excel workbook. Here’s how it worked for me:


set this_file to (((path to desktop folder) as text) & "filename.txt")
tell application "Microsoft Excel"
open text file filename this_file with tab
end tell

there you have it, this should open a txt file in excel. Mind you, the extension of the file is still txt! If you want to save it, here’s what I’ve done then:


set this_file to (((path to desktop folder) as text) & "filename.txt")
tell application "Microsoft Excel"
open text file filename this_file with tab

save active workbook in "insert your path or variable with path here.xls" as default save format
end tell

I hope it gets the work done

greetz

Thanks, but that still gives me the same dialog/error message:

“This file is not in a recognizable format”

It does open once I press “OK”, but I want to avoid that step.

Perhaps “ignoring application responses ----- end ignoring” will do it.

This is what a recording session reveal when opening a sample tab-delimited file and using the default open wizard Excel uses:


tell application "Microsoft Excel"
	OpenText "bootdrive:Users:username:Desktop:testfile.txt" Origin xlMacintosh StartAtRow 1 DataType xlDelimited TextQualifier xlDoubleQuote FieldInfo {{1.0, 1.0}, {2.0, 1.0}, {3.0, 1.0}, {4.0, 1.0}, {5.0, 1.0}, {6.0, 1.0}, {7.0, 1.0}, {8.0, 1.0}, {9.0, 1.0}, {10.0, 1.0}, {11.0, 1.0}, {12.0, 1.0}, {13.0, 1.0}, {14.0, 1.0}, {15.0, 1.0}, {16.0, 1.0}, {17.0, 1.0}} with TabDelimiter without TreatConsecutiveDelimitersAsOne, SemicolonDelimiter, CommaDelimiter, SpaceDelimiter and Other
end tell

Credit to Microsoft, their AppleScript syntax is wonky, but if you use Record, it’s very, very thorough. Usually it’s a bit more than you bargained for.

Looks like this works well enough:


tell application "Microsoft Excel"
	OpenText "bootdrive:Users:username:Desktop:testfile.txt" with TabDelimiter
end tell

Everyone always forgets that Excel is one of the few “recordable” apps around. :wink:

Yeah I don’t have Office 2004, sorry. I only know that the above has worked for Office X and whatever the previous version was. Office 2004 might be two or more versions back. I provided this info on the off chance the command structure has been the same for a while. Guess not. My apologies if it confused anyone.

[EDIT]
I forgot to ask…is Excel 2004 “recordable”?

The dialog box says: “This file is not in a recognizable format”. Once I press “OK”, it opens fine.

The file I’m trying to open is a text file created by Applescript.

Thanks Jacques, that did the trick!