获取选定的数据透视表名称 - Excel VBA

时间:2021-12-08 05:59:53

I have two pivot tables on one excel sheet. I would like to know how do you get the name of a selected pivot table with Excel VBA?

我在一张excel表上有两个数据透视表。我想知道如何使用Excel VBA获取所选数据透视表的名称?

I tried ActiveSheet.PivotTables.Selected, but this is not a supported property.

我尝试过ActiveSheet.PivotTables.Selected,但这不是受支持的属性。

1 个解决方案

#1


8  

You simply use:

你只需使用:

ActiveCell.PivotTable.Name

or, with a bit of error handling:

或者,有一点错误处理:

Dim PT as PivotTable
On Error Resume Next
Set PT = Activecell.PivotTable
On Error Goto 0
If not PT is nothing then msgbox pt.name

#1


8  

You simply use:

你只需使用:

ActiveCell.PivotTable.Name

or, with a bit of error handling:

或者,有一点错误处理:

Dim PT as PivotTable
On Error Resume Next
Set PT = Activecell.PivotTable
On Error Goto 0
If not PT is nothing then msgbox pt.name