AppleScript和Excel 2008数据透视表

创build自动化脚本将Excel列移动到数据透视表时遇到了很多麻烦。 我在OSX 10.8.5上运行没有VB的Excel 2008。 最终目标是将列数据字段转换为行数据字段。

tell application "Microsoft Excel" open file "Users:dkstaff:Desktop:new.xlsx" tell active sheet tell used range set rc to count of rows end tell set myRange to range ("D2:D" & rc) set formula of myRange to "=A2&\":\"&B2&\":\"&C2" # select sourceData insert into range column 4 set header to range "D1" set value of header to "KEY" end tell 

我不知道如何执行所选范围的数据透视表,并把它放在一个新的工作表上。

 -- tell active workbook # new sheet -- set new sheet with name "New Table" # var range of data -- set source_data to range D2:L … of sheet "data" # var sheet -- set PTSheet to the sheet named "pivot Table" # Implement a new Pivot Table from source range -- set pivot_table to make new pivot table at PTSheet with properties source_data tell active workbook set newSheet to make new worksheet at end tell newSheet set name to "Pivot Table" end tell end tell -- Failed attempt thus far... set source_data to range ("D2:L" & rc) of sheet "data" set PTSheet to the sheet named "Pivot Table" set pivot_table to make new pivot table at PTSheet with properties source_data ########## -- Another failed attempt tell active sheet set source_data to range ("D2:L" & rc) of sheet "data" set PTSheet to the sheet named "Pivot Table" set pivot_table to make new pivot table at PTSheet with properties source_data end tell end tell 

结果:错误“Microsoft Excel出错:无法创build类数据透视表”。 从数据透视表到类的数字-2710

我只是无法绕过这个错误。

我在Excel中的工作stream程将是:select列'键' – >数据透视表报表 – >多个合并范围 – >我将创build页面字段 – >范围:data!D $ 2:$ L $ 1500 – >新工作表。

在新的工作表上,双击总和,并显示最终数据。 还有一步,但我不想在这个时候复杂化我的工作stream程。

如果有人有另一种方法来自动从现有的工作表创build一个数据透视表,请提一下,否则,我会继续学习AppleScript,因为我觉得这样做也可以帮助其他任务。