0
我不是AppleScript的專家,因此我試圖找到一個成功處理一批Excel文件的AppleScript代碼示例(每個包含一個工作表),將每個內容複製到一個目標工作表中。AppleScript將多個Excel文件合併到一個工作表中
這是僞代碼,我腦子裏想的:
pick source folder with Excel files;
pick destination Excel file;
for each file within the source folder:
copy data from default sheet;
paste data into destination sheet's first unused row
end
這是我想出了一個代碼。它確實打開每個文件,但複製/過去操作只是沒有發生。任何想法如何讓它工作?
set main_folder to choose folder with prompt "Please select the folder containing the Excel files:"
set target_excel to choose file with prompt "Please select target Excel file:"
set excel_extension_list to {"xls", "xlsx", "csv"}
tell application "Finder"
set excel_files to (files of main_folder whose name extension is in excel_extension_list) as alias list
end tell
tell application "Microsoft Excel"
open target_excel
repeat with a_file in excel_files
open a_file
activate a_file
tell sheet 1 of workbook a_file
set the_range to value of used range
set number_of_source_rows to count of rows of the_range
end tell
activate target_excel
tell sheet 1 of workbook target_excel
set new_range to value of used range
set number_of_destination_rows to count of rows of new_range
set destination_range to range "A" & (number_of_destination_rows + 1) & ":E" & (number_of_destination_rows + 1 + number_of_source_rows)
set value of destination_range to the_range
close workbook a_file saving no
end tell
end repeat
end tell
快速的問題。我相信你在MAC中這樣做?如果是的話,如果你有Office 2011,那麼你也可以使用Excel宏來實現你想要的。 – 2012-08-15 04:23:29
嗨Siddarth - 是的,我在使用Office 2011的Mac上。只要它可以爲我執行批處理(加載每個文件),我會很好地使用宏...我是處理35個文件,我需要每週生成這個報告:/所以如果可行,宏觀的想法是受歡迎的;) – wotaskd 2012-08-15 16:18:02
我已經添加了新的標籤。實際上,大多數Excel VBA也可以與Excel 2011 VBA一起使用。 :) – 2012-08-15 16:33:56