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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25993795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:58:26  来源:igfitidea点击:

Get the selected pivot table name - Excel VBA

excel-vbapivot-tablevbaexcel

提问by Jason Samuels

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,但这不是受支持的属性。

回答by Rory

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