共用方式為


PivotCaches.Create 方法 (Excel)

用來建立新的 PivotCache。

語法

表達。建立 (SourceTypeSourceData版本)

代表 PivotCaches 物件的變數。

參數

名稱 必要/選用 資料類型 描述
SourceType 必要 XlPivotTableSourceType SourceType 可以是下列其中一個 XlPivotTableSourceType 常數: xlConsolidationxlDatabasexlExternal
SourceData 選用 Variant 新 PivotTable 快取的資料。
版本 選用 Variant 樞紐分析表的版本。 Version 可以是其中一個 XlPivotTableVersionList 常數。

傳回值

PivotCache

註解

使用此方法建立樞紐透視快取時,不支援下列兩個 XlPivotTableSourceType 常數: xlPivotTablexlScenario。 如果提供這兩個常數其中一個,便會傳回執行階段錯誤。

如果 SourceType 不是 xlExternal,就需要 SourceData 引數。 當 SourceTypexlConsolidationxlDatabase) 時,應該 (傳遞 Range 物件,或當 SourceTypexlExternal) 時 (WorkbookConnection 物件。

傳遞 Range 物件時,建議您使用字串來指定活頁簿、工作表和儲存格範圍,或設定具名範圍並將名稱作為字串傳遞。 傳遞 Range 物件可能會意外導致「類型不相符」錯誤。

如果未提供,樞紐分析表的版本會是 xlPivotTableVersion12。 不允許使用 xlPivotTableVersionCurrent 常數,而且如果提供 xlPivotTableVersionCurrent 常數,則會傳回執行階段錯誤。

範例

下列程式碼範例會定義連線,然後建立 樞紐分析快取的連線。

Workbooks("Book1").Connections.Add2 _
    "Target Connection Name", "", Array("OLEDB;Provider=MSOLAP.5;Integrated Security=SSPI;Persist Security Info=True;Data Source=##TargetServer##;Initial Catalog=Adventure Works DW", ""), 
    "Adventure Works", 1
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, SourceData:=ActiveWorkbook.Connections("Target Connection Name"), _ 
    Version:=xlPivotTableVersion15).CreatePivotChart(ChartDestination:="Sheet1").Select

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應