Macro to pull a list of all PivotTable Fields from an OLAP CUBE

im2bz2p345

Board Regular
Joined
Mar 31, 2008
Messages
226
Hi all,

Is there a way to pull all PivotTables fields when connected to a OLAP cube?

I found this topic on OZGrid with a similar request: Listing Pivottable Field List Fields - OzGrid Free Excel/VBA Help Forum

Post#8 has the code which I need (copy-pasted below) but that post is from 2006 and every time that I try to run that code, it gives me a Run-time error '9' subscript out of range error on this line:
For Each objCubeFld In Worksheets("PivotTable Data").PivotTables(1).CubeFields

VBA Code:
Sub list_cube_fields()
 Set objNewSheet = Worksheets.Add
 objNewSheet.Activate
 intRow = 1
 For Each objCubeFld In Worksheets("PivotTable Data").PivotTables(1).CubeFields
 objNewSheet.Cells(intRow, 1).Value = objCubeFld.Name
 intRow = intRow + 1
 Next objCubeFld
 
End Sub

I don't know VBA too well, but I did try changing .PivotTables(1) to .PivotTables1 (since my PivotTable is named PivotTables1), but that didn't help.

Does anyone know what to change to get this code to work? For reference, I'm running the 32-bit MS Excel 365 MSO (16.0.13801.21050) version.

Ty in advance for any help on this,

~ im2bz2p345 :)
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top