overwrite in Excel
I'm trying to edit I found online for batch converting Excel files to CSV files, and I want to overwrite files of the same name in the folder where I am dumping the converted CSV files. How do I get Excel to overwrite a file I am saving as a CSV? Here's the script I have so far:
set theFolder to choose folder with prompt "Choose the folder that contains your Excel files" default location path to desktop
set theSaver to choose folder with prompt "Choose the folder that will contain your CSV files" default location path to desktop
tell application "Finder" to set theFiles to (files of entire contents of theFolder)
set fileCount to count theFiles
repeat with i from 1 to fileCount
set fName to text 1 thru -5 of ((name of item i of theFiles) as text)
if ((name of item i of theFiles) as text) ends with ".xls" then
set tName to (theSaver as text) & fName & ".csv"
tell application "Microsoft Excel"
activate
set overwrite to true
open (item i of theFiles) as text
save fName in tName as CSV file format
close active workbook without saving
end tell
end if
end repeat
set theFolder to choose folder with prompt "Choose the folder that contains your Excel files" default location path to desktop
set theSaver to choose folder with prompt "Choose the folder that will contain your CSV files" default location path to desktop
tell application "Finder" to set theFiles to (files of entire contents of theFolder)
set fileCount to count theFiles
repeat with i from 1 to fileCount
set fName to text 1 thru -5 of ((name of item i of theFiles) as text)
if ((name of item i of theFiles) as text) ends with ".xls" then
set tName to (theSaver as text) & fName & ".csv"
tell application "Microsoft Excel"
activate
set overwrite to true
open (item i of theFiles) as text
save fName in tName as CSV file format
close active workbook without saving
end tell
end if
end repeat