PivotTables.Add メソッド (Excel)

新しいピボットテーブル レポートを追加します。 PivotTable オブジェクトを返します。

構文

Add (PivotCacheTableDestinationTableNameReadDataDefaultVersion)

ピボットテーブル オブジェクトを表す変数。

パラメーター

名前 必須 / オプション データ型 説明
PivotCache 必須 PivotCache 作成するピボットテーブル レポートの基になるピボットテーブル キャッシュを指定します。 このキャッシュにより、レポートのデータが提供されます。
TableDestination 必須 バリアント型 (Variant) ピボットテーブル レポートの配置先範囲 (結果のレポートを配置するワークシートの範囲) の左上端のセルを指定します。 で指定されたピボットテーブル オブジェクトを含むワークシートで、コピー先の範囲を指定する必要があります。
TableName 省略可能 バリアント型 (Variant) 作成するピボットテーブル レポートの名前を指定します。
ReadData 省略可能 バリアント型 (Variant) True を指定 すると、外部データベースのすべてのレコードを含むピボットテーブル キャッシュが作成されます。このキャッシュは非常に大きくなる可能性があります。 False を 指定すると、データを実際に読み取る前に、一部のフィールドをサーバー ベースのページ フィールドとして設定できます。
DefaultVersion 省略可能 バリアント型 ピボットテーブルが最初に作成された Microsoft Excel のバージョン。

戻り値

新しいピボットテーブル レポートを表す PivotTable オブジェクト。

この例では、OLAP プロバイダーに基づいて新しいピボットテーブル キャッシュを作成し、最初のワークシートのセル A1 のキャッシュに基づいて新しいピボットテーブル レポートを作成します。

Dim cnnConn As ADODB.Connection 
Dim rstRecordset As ADODB.Recordset 
Dim cmdCommand As ADODB.Command 
 
' Open the connection. 
Set cnnConn = New ADODB.Connection 
With cnnConn 
 .ConnectionString = _ 
 "Provider=Microsoft.Jet.OLEDB.4.0" 
 .Open "C:\perfdate\record.mdb" 
End With 
 
' Set the command text. 
Set cmdCommand = New ADODB.Command 
Set cmdCommand.ActiveConnection = cnnConn 
With cmdCommand 
 .CommandText = "Select Speed, Pressure, Time From DynoRun" 
 .CommandType = adCmdText 
 .Execute 
End With 
 
' Open the recordset. 
Set rstRecordset = New ADODB.Recordset 
Set rstRecordset.ActiveConnection = cnnConn 
rstRecordset.Open cmdCommand 
 
' Create PivotTable cache and report. 
Set objPivotCache = ActiveWorkbook.PivotCaches.Add( _ 
 SourceType:=xlExternal) 
Set objPivotCache.Recordset = rstRecordset 
 
ActiveSheet.PivotTables.Add _ 
 PivotCache:=objPivotCache, _ 
 TableDestination:=Range("A3"), _ 
 TableName:="Performance" 
 
With ActiveSheet.PivotTables("Performance") 
 .SmallGrid = False 
 With .PivotFields("Pressure") 
 .Orientation = xlRowField 
 .Position = 1 
 End With 
 With .PivotFields("Speed") 
 .Orientation = xlColumnField 
 .Position = 1 
 End With 
 With .PivotFields("Time") 
 .Orientation = xlDataField 
 .Position = 1 
 End With 
End With 
 
' Close the connections and clean up. 
cnnConn.Close 
Set cmdCommand = Nothing 
Set rstRecordSet = Nothing 
Set cnnConn = Nothing

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。