Excel の列をピボットテーブルに移動するための自動化スクリプトを作成するのに非常に苦労しています。VB なしで Excel 2008 を実行している OSX 10.8.5 を使用しています。最終的な目標は、列データ フィールドを行データ フィールドに変換することです。
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 でエラーが発生しました: クラス ピボット テーブルを作成できません。」ピボット テーブルからクラスへの数値 -2710
このエラーを回避することはできません。
Excel での私のワークフローは次のようになります: 列 'キー' を選択 -> ピボットテーブル レポート -> 複数の統合範囲 -> ページ フィールドを作成します -> 範囲: データ!D$2:$L$1500 -> 新しいシート。
新しいシートで、総計をダブルクリックすると、最終データが表示されます。もう 1 つステップがありますが、現時点ではワークフローを過度に複雑にしたくありません。
既存のシートからのピボット テーブルの作成を自動化する別の方法を誰かが持っている場合は、そのことを伝えてください。それ以外の場合は、AppleScript の学習を続けたいと思います。他のタスクにも役立つと思うからです。