Cannot open files in Excel from Applescript!

(Forgive me if this is a duplicate post. I wasn’t certain the first attempt got through.)

Hi All,

No matter what I do, I’m unable to open a text file into Excel.

I’m using OS X v 10.2.6 and v.X SR1 of Office.

Here’s the AppleScript code I’m using:


		tell application "Microsoft Excel"

			Activate

			OpenText "Mobile Bug Data:Users:img_meister:Public:ROS_107_20011112e_DATA.txt" Origin xlMacintosh StartAtRow 1 DataType xlDelimited TextQualifier xlDoubleQuote FieldInfo l_lstFieldInfo with CommaDelimiter

		end tell
		

Here’s the error I get:

‘Microsoft Excel got an error: “Mobile Bug Data:Users:img_meister:Public:ROS_107_20011112e_DATA.txt” doesn’t understand the OpenText message.’

This same file can be easily imported directly into Excel without a problem.

This same code used to work under OS 9. I’m sure many other folks are able to do this under OS X. Is there a bug fix or upgrade to Office that might fix this?

Many thanks ahead of time for any help you can offer.

Cheers,
Bill Bug

:cry:

Are you sure the exact same code worked under Mac OS 9.x?

Looking at the Excel dictionary, I see:

OpenText: Open an object
	OpenText reference  -- file to open
 		[Origin xlMacintosh/xlWindows/xlMSDOS] -- where file was created
 		[StartAtRow integer] -- row to start importing a text file at
blah, blah, blah

where the first parameter is a reference to the file to open.

In your case you’ve just passed it a string. There is no direct relationship between a string and a file unless you create one.

Try changing the OpenText command to say:

     OpenText [b]file[/b] "Mobile Bug Data:Users:img_meister:Public:ROS_107_20011112e_DATA.txt" Origin xlMacintosh StartAtRow 1 DataType xlDelimited TextQualifier xlDoubleQuote FieldInfo l_lstFieldInfo with CommaDelimiter 

and see if that makes any difference.

Thanks for the suggestion.

This code did work before I ported it to OS X. I was using OS 9.2.2 and Office 2001 SR1.

Once things stopped working under OS X, I tried casting the file name as a ‘string’ and as ‘text’. I also tried sending it as a ‘file’ reference or ‘alias’. None of these work. They all result in exactly the same error.

The error indicates the ‘OpenText’ AppleEvent is being sent to the file itself.

Microsoft Excel got an error: “Mobile Bug Data:Users:img_meister:Public:ROS_107_20011112e_DATA.txt” doesn’t understand the OpenText message

I’m not sure why this would be. The syntax is literally cut-and-pasted straight from the dictionary.

Thanks again for your feedback.

Cheers,
Bill