AppleScript: Save As Text (Tab Delimited)

R

ray

I'm trying to find the AppleScript equivalent of saving a sheet as tab-
delimited text, but I'm either misunderstanding the available "as"
constants, or have run into a bug. I'm using Excel 11.3.3 under OS
10.4.9 on an Intel-based Mac.

Example:

tell application "Microsoft Excel"
save active workbook in (folderPath & textFileName) as text Mac
end tell

This does indeed save the active sheet as tab-delimited text. The
problems:

*Cells which are formatted as dates dd-mon-yy change the year to four
digits
*Cells which are formatted "#,##0.00" drop any trailing zeros

This is *not* the case when I manually save a file as Text (Tab
Delimited). The text stays the same as it appears in the worksheet.

However, the problem also occurs if I use copy range to put the text
on the clipboard. Is this a bug?

So far, I'm considering the option of repeating through each cell to
get the string value, or GUI scripting the Save As process. Neither is
a great alternative.

Thanks in advance for any help.

Ray Robertson
AppleScript Pro Sessions Denver, June 18-22
<http://scriptingmatters.com/aspro>
 
J

JE McGimpsey

tell application "Microsoft Excel"
save active workbook in (folderPath & textFileName) as text Mac
end tell

This does indeed save the active sheet as tab-delimited text. The
problems:

*Cells which are formatted as dates dd-mon-yy change the year to four
digits
*Cells which are formatted "#,##0.00" drop any trailing zeros

This is *not* the case when I manually save a file as Text (Tab
Delimited). The text stays the same as it appears in the worksheet.

However, the problem also occurs if I use copy range to put the text
on the clipboard. Is this a bug?

I can't reproduce this fully with my setup (XL11.3.5, but I don't think
that would have changed since 11.3.3).

The generated text file indeed has four-digit years, but the trailing
zeros show up fine in my limited testing.

However, the clipboard pastes fine into TextEdit. Normally, the
clipboard will have several versions saved so that the target
application can choose the appropriate one. What are you doing with the
clipboard to see the same problems?

I've put a note into MacBU to see if that's a known bug. No telling
if/when they'll respond.
 

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