无法通过VBA中的字符串值访问Excel数据透视表字段

时间:2018-04-26 17:08:20

标签: excel vba excel-vba pivot-table

我正在尝试通过VBA宏访问Excel电子表格中的行字段

Sub EnableSelectionSelPF()
'pivot table tutorial by contextures.com

'This is the Excel Module that will enable
'the selection for a single piviot table
'column on the first table of the sheet

Dim PT As PivotTable
Dim PF As PivotField
Dim Column As String

Column = "Service Address"

On Error Resume Next
Set PT = ActiveSheet.PivotTables(1)
Set PF = PT.RowFields(Column)
    PF.EnableItemSelection = True
End Sub

当用数字索引值替换列字符串变量时,我能够访问所需的字段,但是尝试使用字符串变量Column或字符串值作为索引不会产生任何结果为了我。

我已经检查过以确保PT.RowFields()可以使用字符串值,因此我不太确定问题是什么。

基本代码来自:Contextures

0 个答案:

没有答案