Disclaimer: This question was posted in msdn forum but since I didn't get any reply (surprisingly), I am cross posting it here as well. You might want to check that link before you try to attempt this question. I wouldn't want you to waste your time if a solution was posted in that link :)
Problem: I want to find out the field names in the Report Filter. So I am looking for RegionCountryName
, Cityname
and ProductKey
. The Report Filters are dynamic and can change.
Screenshot:
What have I tried: I have checked every property of the Power Pivot but there is no property that I could find which would let me loop through the fields of the power pivot.
I have even tried this code but it apparently give me an error on Set pf = pt.PageFields(1)
Sub Sample()
Dim pt As PivotTable, pi As PivotItem, pf As PivotField
Dim lLoop As Long
Set pt = Sheet1.PivotTables(1)
Set pf = pt.PageFields(1)
For Each pi In pf.PivotItems
Debug.Print pi.Name
Next pi
End Sub
Error ScreenShot
So what am I missing? Or is there a different approach that I should take?
EDIT
If someone wants to experiment with it, the file can be downloaded from HERE I am looking at the Inventory
Sheet.