How to traverse excel files/sheets within a folder to delete specified columns.
I am working on Excel. We have a little over 25,000 excel WORKBOOKS that need 2 columns deleted from each of their sheets within. (Meaning if all 25k had 1 sheet, we should be deleting 50k columns.) But most of them have multiple sheets in them.
So far this is what I have...
set sourcefilepath to (choose folder) as alias
tell application "Finder" to set sourcefiles to ¬
(every file in the folder sourcefilepath whose ¬
name ends with ".xlsx") as alias list
tell application "Finder"
set filecount to count files in the entire contents of sourcefilepath
tell application "Microsoft Excel" to open the sourcefiles
repeat filecount times
set myValues to "Prod Alpha, Warehouse No"
tell application "Microsoft Excel"
activate
set mysheets to every sheet of active workbook
repeat with asheet in mysheets
tell asheet
set columnCount to (((count of columns of used range of active sheet)) + 1)
repeat with i from columnCount to 1 by -1
set cellValue to value of row 1 of column i
if cellValue is in myValues then
delete column i
end if
end repeat
end tell
end repeat
close active workbook
end tell
end repeat
end tell
The problem is when it opens all the sheets, everything (for obvious reasons) slows down. Then it gets about half way through the files ands stops. Leaving 1/2 still open with no changes.
Is there a reason? and is there a better why I can structure this to maybe open 1, do the operations, save it, close it, then move to another?