Correction: Your solution DOES NOT WORK: The individual worksheets do
NOT get saved as CSV, they still get saved as .XLS workbooks. I think
that's because of the use of "save workbook" instead of "save as
(sheet)".
So, here is my final solution, for the benefit of others. I have now
added the ability for the user to enter which sheets get saved as CSV.
set theFile to choose file
display dialog "Enter sheets to save (comma-delimited)" default answer
"1"
set theList to text returned of the result
try
set oldDelims to AppleScript's text item delimiters -- save their
current state
set AppleScript's text item delimiters to {","} -- declare new
delimiters
set sheet_list to every text item of theList
set AppleScript's text item delimiters to oldDelims -- restore them
on error
set AppleScript's text item delimiters to oldDelims -- restore them
in case something went wrong
end try
tell application "Microsoft Excel"
activate
open theFile
repeat with i in sheet_list
my save_sheet(i as integer)
end repeat
close active workbook without saving
end tell
on save_sheet(i)
tell application "Microsoft Excel"
set sheet_name to name of sheet i
set fname to (full name of active workbook)
set fname to text 1 thru -5 of fname --remove file extension
set tname to fname & "_" & sheet_name & ".csv"
copy worksheet sheet i
--save workbook as active workbook filename tname file format CSV
save as (sheet 1) filename tname file format CSV
close active workbook without saving
end tell
end save_sheet
> In article <1190584966.461719.262...@k79g2000hse.googlegroups.com>,
>
[quoted text clipped - 5 lines]
> worksheet necessarily requires saving its parent workbook. It's not that
> difficult to copy the sheet to a new workbook and save it.
I strongly disagree. Why would exporting a worksheet "necessarily
require" saving its parent workbook? Incidentally, I am going through
all of this because, unfortunately, people keep sending me files in
proprietary Office formats. I really need Excel only to export these
files so I can use the program I WANT to process my files. I would be
much better off if people would use only ASCII text files in this
case.
Also, sometimes I get really large files. Having to copy them to a new
workbook is very inefficient and a waste of resource and processing
time. I guess it's kind of the "Microsoft Office" way of doing things.
No thanks.
> > Waiting for the port of OpenOffice with Aqua GUI to completely ditch
> > M$ Office from my computer.
>
> NeoOffice has had an Aqua GUI for a long time:
>
> http://www.neooffice.org/
I know, but that is excruciatingly slow (maybe because of its use of
Java).
> OpenOffice has an alpha available
>
> http://porting.openoffice.org/mac/download/aqua.html
Yes, but after reading their warning about not using the software on a
production machine, I prefer to hold off...
> However, IIRC, both mimic XL's Save As behavior, and neither have
> AppleScript support, so I'm not sure what you're expecting to be
> better...
Well, for one, it will be FREE.
In time, OpenOffice will completely replace Office. Or at least,
that's what I hope.