I have a script that combines multiple excel files in a chosen folder into a single excel file. the script works fine, but when saved as an app or run-only an error pops up at the very end to the effect of “COuld not save changes, OSA Error -2707”
Any ideas?
It doesn’t affect the script really, because I still get the final combined file in the end, it’s mostly annoying.
Any help is [as always] greatly appreciated.
Here’s the code:
set oldDelims to AppleScript's text item delimiters
set i to 0
tell application "Finder"
set the_Folders to choose folder with prompt "Choose the folder of Tracking files to combine."
set List_of_Files to every file in the_Folders
set StartDate to current date
set theday to day of StartDate
set theyear to characters 3 thru 4 of (year of StartDate as string) as string
set themonth to characters 1 thru 3 of (month of StartDate as string) as string
set TodaysDated to (themonth & "-" & theday & "-" & theyear) as string
set Target_File to ("PT_Summary_" & TodaysDated as string)
set the_chosen_saving_folder to choose folder with prompt "Choose the folder you'd like to save your summary file to."
set the_chosen_saving_folder to the_chosen_saving_folder as string
duplicate alias "CS_Resources:Job_Tracking:Print Production Tracking:PP-Tracking_Templates:PT Main_Read-Only.xls" to alias the_chosen_saving_folder
set name of result to Target_File
end tell
tell application "Microsoft Excel"
activate
set Target_File to (the_chosen_saving_folder & Target_File) as string
open Target_File
set ColumnAStart to 2 --starts right after main heading, variable set to move down rows when pasting
set first_content_row to 2
repeat with i from 1 to count of items of List_of_Files
set Copied_File to item i of List_of_Files
open Copied_File
activate Copied_File
set Column_to_Search to range "E:E" --search this column
set cell_to_start_search_after to range "E1" --begin search after this cell
set empty_cell_search to find Column_to_Search what "" after cell_to_start_search_after look in values look at whole search direction search next --look for empty cell in given range
set empty_cell to get address empty_cell_search --set address of empty cell to string
set AppleScript's text item delimiters to "$" --look for column and row references
set last_column_copied to text item 3 of empty_cell --row reference
set AppleScript's text item delimiters to ""
set content_copied to value of range ({"$A$2:$GB$" & (last_column_copied)} as string) --copies range of cells using row reference variable
close active workbook without saving
activate Target_File
set Target_Column_searched to range "E:E"
set Target_cell_to_search_after to range "E1"
set Target_empty_cell_search to find Target_Column_searched what "" after Target_cell_to_search_after look in values look at whole search direction search next
set firstMainEmptyCell to get address Target_empty_cell_search
set AppleScript's text item delimiters to "$" --look for column and row references
set theEmptyMainRow to text item 3 of firstMainEmptyCell
set first_content_row to (theEmptyMainRow + (last_column_copied - 3))
set AppleScript's text item delimiters to ""
set Area_for_copied_content to range ({"$A$" & theEmptyMainRow & ":$GB$" & first_content_row} as string)
copy contents of content_copied to value of Area_for_copied_content
end repeat
display dialog "All done!"
end tell
set AppleScript's text item delimiters to oldDelims
Model: g5
AppleScript: Script Editor
Browser: Safari 419.3
Operating System: Mac OS X (10.4)