我正在嘗試使用 VBA 創建資料透視表,但遇到以下錯誤:
“運行時錯誤‘5’:
無效的程序呼叫或引數”
現在,我使用這個問題/答案來嘗試解決我的問題Runtime Error 5 Sometimes in VBA Creating PivotTable
我記錄了我的宏,看看如果我正常制作資料透視表會產生什么代碼。我將使用名為“報告”的現有作業表創建資料透視表。結果如下:(我洗掉了這段代碼中的大部分代碼,因為很多是資料透視表屬性 True/False 等)
Range("A3:CX1048576").Select
Range("F3816").Activate
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"OrderManagementData!R3C1:R1048576C102", Version:=8).CreatePivotTable _
TableDestination:="Stock & WIP Report!R1:R1048576", TableName:= _
"PivotTable2", DefaultVersion:=8
Sheets("Report").Select
Cells(1, 1).Select
With ActiveSheet.PivotTables("PivotTable1")
.ColumnGrand = True
.RowAxisLayout xlCompactRow
End With
With ActiveSheet.PivotTables("PivotTable1").PivotCache
.RefreshOnFileOpen = False
.MissingItemsLimit = xlMissingItemsDefault
End With
ActiveSheet.PivotTables("PivotTable1").RepeatAllLabels xlRepeatLabels
現在,當我除錯錯誤時,它突出顯示了這部分代碼:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"OrderManagementData!R3C1:R1048576C102", Version:=8).CreatePivotTable _
TableDestination:="Stock & WIP Report!R1:R1048576", TableName:= _
"PivotTable2", DefaultVersion:=8
我嘗試將版本/默認版本更改為以下任何一個:xlPivotTableVersion15、xlPivotTableVersion14、xlPivotTableVersion12 但沒有任何效果。
我的 Excel 版本不只是 2010 或 2013。當我單擊檔案 -> 帳戶 -> 關于 Excel 時,它會顯示以下資訊: Microsoft? Excel? for Microsoft 365 MSO (Version 2210 Build 16.0.15726.20070) 64-bit
知道如何創建資料透視表嗎?花了一段時間,我很難過
uj5u.com熱心網友回復:
嘗試以下操作:
TableDestination:="Stock & WIP Report!R1C1"
或者
TableDestination:=ThisWorkbook.Worksheets("Stock & WIP Report").Range("A1")
請注意,Version:=8和DefaultVersion:=8都是可選引數,如PivotCaches.Create和PivotCache.CreatePivotTable檔案中所述。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/534672.html
標籤:擅长VBA
上一篇:覆寫VBA中現有資料之前的警告
