Skip to content
Advertisement

How to get the Pivot table name and pivot field name of the selected or active cell using Excel JavaScript API?

I am new to Excel JavaScript API.

My question is

How to get the Pivot table name and pivot field name of the selected or active cell using Excel JavaScript API?

how to get the same result with excel JS as we are getting from the below VBA code?

Sub GetPivotName()

Range("C2") = ActiveCell.PivotTable.Name

End Sub

Advertisement

Answer

Have you tried Range.getPivotTables API to get the pivot tables? In the link there’s also a piece of example code.

To get pivot fields, currently as far as I know you’ll have to iterate through all pivot fields in the pivot tables to find out (via PivotHierarchy, as demonstrated here). As someone else has asked in Excel Range.PivotField equivalent for JavaScript API, currently there isn’t a JS equivalent of Range.PivotField in VBA. If you’d like to request for this feature, please feel free to post it to Microsoft 365 Developer Platform Ideas Forum.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement