Hello. I have a spreadsheet with a pivot table. I created the spreadsheet by copying data in it and then inserted a Pivot Table which works fine. I am trying to see the SQL code for the pivot table. I inserted the following code in Modules. You can see the different responses I get after each msgbox. There are other properties that show and several that give me the same error.
I do not know how to get the CommandText which I understand should contain the SQL for the Pivot table. Please help. Thank you
Public Sub CommandButton2_Click()
Dim pc As PivotCache
Set pc = ActiveWorkbook.PivotCaches(1)
MsgBox "PC1 " & pc.Index ' "PC1 1"
MsgBox "PC1 " & pc.Application ' "PC1 Microsoft Excel"
MsgBox "PC1 " & pc.RecordCount ' "PC1 6791"
MsgBox "PC1 " & pc.Version ' "PC1 4"
MsgBox "PC1 " & pc.CommandText ' "Runtime Error 1004"
End Sub
I do not know how to get the CommandText which I understand should contain the SQL for the Pivot table. Please help. Thank you
Public Sub CommandButton2_Click()
Dim pc As PivotCache
Set pc = ActiveWorkbook.PivotCaches(1)
MsgBox "PC1 " & pc.Index ' "PC1 1"
MsgBox "PC1 " & pc.Application ' "PC1 Microsoft Excel"
MsgBox "PC1 " & pc.RecordCount ' "PC1 6791"
MsgBox "PC1 " & pc.Version ' "PC1 4"
MsgBox "PC1 " & pc.CommandText ' "Runtime Error 1004"
End Sub