O$: opening txt file in Excel via Applescript

Keith Bartlett keith at adnetltd.co.uk
Fri Dec 9 03:33:30 EST 2011

Hi Andrew

Had lots of problems with files being open & even Excel itself being open on some occasions, so we just check if Excel is already running and prompt the user to close it.  Not ideal but it works.


On 9 Dec 2011, at 00:17, Andrew Pavey wrote:

> Thanks Reg, good to know it's not just me.
> any insight on the second problem?
> "if the txt file is already open in Excel I get an error in setting 
> the export path, there appears to be no way in Studio to trap this 
> error."
> At 9:55 AM +1100 9/12/11, Reg Paling wrote:
>> Hi Andrew,
>> Here's a snippet from my code:
>> Do $runapplescript(lvScript) Returns lvResult
>> If lvResult=0     ;; 0 is good...
>> Else If lvResult=-1753     ;; Don't know what this error code means 
>> but it appears to be OK (This error comes from the Word object)
>> Else
>>   Quit method 0 ;; return an error to my calling method in Omnis 
>> (my convention is 1 is good)
>> End If
>> - - This is part of a method that establishes a connection to Word 
>> or Excel, before even trying to open a file.
>> - - The upshot of this is I just ignore the -1753 error and treat 
>> it as success (equivalent to 0).
>> - - I recall I invested/wasted some considerable time on this.  In 
>> the end the code above ran OK for years in at least 1 site.
>> Cheers,
>> Reg
>> On 9/12/11 8:55 AM, Andrew Pavey wrote:
>>> I have the following code (which runs perfectly in Apple's Script 
>>> Editor) to open a tab delimited text file just created in Studio 
>>> (v5.1). The really nice bit of this code is the autofit line which 
>>> resizes the columns to the max size of the data in the column.
>>> Begin text block
>>> Text: tell application "Microsoft Excel" (Carriage return)
>>> Text: activate (Carriage return)
>>> Text: open "[pFilePath]" (Carriage return)
>>> Text: " (Carriage return)
>>> Text: autofit (columns of used range of active sheet) (Carriage 
>>> return)     ;; thank you Paul Berkowitz
>>> Text: " (Carriage return)
>>> Text: end tell (Carriage return)
>>> End text block
>>> when I run this using
>>> Do $runapplescript(lvScript,lvResult) Returns lvErrCode
>>> I occasionally get a -1753 error. It was happening yesterday 
>>> afternoon, and this morning it isn't (grrr!!)
>>> Can anyone tell me where the -1753 error comes from, and/or where 
>>> I'd get a lookup list of that error code set?
>>> Additionally, if the txt file is already open in Excel I get an 
>>> error in setting the export path, there appears to be no way in 
>>> Studio to trap this error. My work around has been to always create 
>>> a unique file name before attempting to open the txt  file in 
>>> Excel, but it would be nice to have a way of determining if the 
>>> file was already open.
>>> At this stage I'm only working on Macs.
>>> TIA
>>> Andrew Pavey
>> _____________________________________________________________
>> Manage your list subscriptions at http://lists.omnis-dev.com
> -- 
> Web pages: http://www.spelean.com.au    email: info at spelean.com.au
> Phone: (+61) 2 9966 9800, Fax: (+61) 2 9966 9811
> PO Box 645, ARTARMON, NSW, 1570, Australia.
> _____________________________________________________________
> Manage your list subscriptions at http://lists.omnis-dev.com

Keith Bartlett
Adnet Ltd - (0)1491 642133

 This message contains information from Adnet Ltd which may be privileged  
 or confidential.  If you are not the intended recipient be aware that any  
 disclosure, copying, distribution or use of the contents of this mail is 
 prohibited.  If you have received this message in error, please notify us 
 immediately and then delete this mail from your system.

More information about the omnisdev-en mailing list