我正在使用 excel 2013,并且在调用 PivotCaches.Add 时收到无效的过程调用或参数
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set ActiveWorkbook = objExcel.Workbooks.Open("C:\Users\srujan\Desktop\TIME REPORT\fresh\25_Report Time Booking_25.xls")
ActiveWorkbook.Sheets("25_Report Time Booking_25").Select
' Set the range to be pivoted to be called PivotRange
Set PivotTopLeft = ActiveWorkbook.Parent.Worksheets("25_Report Time Booking_25").Range("A1")
Set PivotTopRight = PivotTopLeft.Range("G1")
Set PivotTop = ActiveWorkbook.Parent.Worksheets("25_Report Time Booking_25").Range(PivotTopLeft, PivotTopRight)
Set MyPivotRange = ActiveWorkbook.Parent.Worksheets("25_Report Time Booking_25").Range(PivotTop, PivotTop.Range("G78"))
' Create the pivot table
'ActiveWorkbook.CutCopyMode = False
ActiveWorkbook.Parent.Worksheets.Add
MyPivotRangeName = "'" & MyPivotRange.Parent.Name & "'" & "!" & MyPivotRange.Address(ReferenceStyle = xlR1C1)
MsgBox (MyPivotRangeName)
Set MyPivotCache = ActiveWorkbook.PivotCaches.Add(SourceType = xlDatabase, SourceData = MyPivotRangeName)
MyPivotCache.CreatePivotTable TableDestination = (ActiveWorkbook.Parent.Worksheets("Sheet1").Range("A3")), TableName = "PivotTable1"
ActiveWorkbook.Parent.Worksheets("Sheet1").PivotTables("PivotTable1").PivotTableWizard
ActiveWorkbook.Parent.Worksheets("Sheet1").PivotTables("PivotTable1").SmallGrid = False
ActiveWorkbook.Parent.Worksheets("Sheet1").PivotTables("PivotTable1").AddFields RowFields = "Activity Type", PageFields = "User"
With ActiveWorkbook.Parent.Worksheets("Sheet1").PivotTables("PivotTable1").PivotFields("Effort Spent (Hrs)" & Chr(10) & "($)")
.Orientation = xlDataField
.Function = xlSum
.NumberFormat = "#,##0"
End With
With ActiveWorkbook.Parent.Worksheets("Sheet1").PivotTables("PivotTable1").PivotFields("Activity Type")
.PivotItems("ANALYSIS").Visible = False
.PivotItems("BUILD").Visible = False
.PivotItems("CARRIERSAP").Visible = False
.PivotItems("HOWTO").Visible = False
.PivotItems("MAINTENANC").Visible = False
.PivotItems("MAINTENANCE").Visible = False
.PivotItems("REVIEW").Visible = False
.PivotItems("STX-SCRIPT").Visible = False
.PivotItems("(blank)").Visible = False
End With