Using Excel 2013, I'm trying to create a pivot table in a workbook using an existing Power Pivot Model using the PivotTables.Add method. There seems to be a problem with my PivotCache. Here is what I've done so far:
Dim pc As PivotCache, i As Long
'
i = 1
For Each pc In ActiveWorkbook.PivotCaches
Range("a" & i).Value = pc.Index
Range("b" & i).Value = pc.CommandText
i = i + 1
Next
Produces This:
1 Model
2 Model
3 Model
However, running the below throws up a run time error:
Range("a1").Select
ActiveSheet.PivotTables.Add _
PivotCache:=ActiveWorkBook.PivotCaches(1), _
TableDestination:=Range("A3")
The error is:
Run-time Error '1004':
Application-defined or object-defined error
The error occurs with all three available PivotCache indexes (1-3).
FWIW, I can add a PivotTable manually under the PowerPivot ribbon. Manage > Home > PivotTable. I'm trying to accomplish the same thing in VBA. Incidentally, record macro doesn't record anything until I begin manipulating the PivotTable I just created.
Any help would be greatly appreciated.
Thanks...Josh