I tested the same code below after recording the macro and it works.
So, I saved it as an xla add-in and ran the same code. It creates the pivot table
but I get the error below when it is about to fill the data for the row
Run-time Error '91':Object Variable or With block variable not set
This error on the procedure Sub Test() below occurs at line ActiveWorkbook.PivotTableWizard. How should I fix this?
Sub Test()
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"print_logs!R3C1:R6C40").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
********* Error Message shows when executing line below
ActiveWorkbook.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:="Comment", _
ColumnFields:="Paper Size"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Total Pages").Orientation _
= xlDataField
End Sub
Bookmarks