會新增樞紐分析表。 傳回 樞紐分析表 物件。
語法
表達。新增 (PivotCache、TableDestination、TableName、ReadData、DefaultVersion)
詞 代表 樞紐分析表 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| PivotCache | 必要 | PivotCache | 建立新樞紐分析表時所根據的樞紐分析表快取。 快取會提供資料給報表。 |
| 表格目的地 | 必要 | Variant | 位於樞紐分析表目的範圍 (即工作表上將要放置結果報表的範圍) 左上角的儲存格。 您必須在包含 expression 所指定之 PivotTables 物件的工作表上指定目的範圍。 |
| TableName | 選用 | Variant | 新的資料樞紐分析表的名稱。 |
| 讀取資料 | 選用 | Variant | 如果為 True,則會建立包含外部資料庫中所有記錄的樞紐分析表快取,此快取可能非常大。 False,允許在實際讀取資料前將部分欄位設定為伺服器型態的頁面欄位。 |
| 預設版本 | 選用 | Variant | 最初建立樞紐分析表的 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 支援與意見反應。