错误1004:无法设置Pivot Item类的Visible属性

时间:2017-07-25 21:13:59

标签: excel-vba vba excel

下面是vba脚本,我的数据透视表不会更新。 Pivot.Items设置为False如何解决这个问题?

objWB.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
wsData & "!R1C1:R65536C7", Version:=xlPivotTableVersion12).CreatePivotTable _
TableDestination:="'" & wsName & "'!R3C1", TableName:=wsName, DefaultVersion _
:=xlPivotTableVersion12

With objWS.PivotTables(wsName).PivotFields("Team")     '1st pivot field selected from data table
    .Caption = "Team"                                      ' rename field for cleaner look
    .Orientation = xlRowField                               ' this is a row field
    .Position = 1                                           ' this is the 1st level row field
    .PivotItems("(blank)").Visible = False                  ' hide/filter fields with (blank value) - this needs to be done since we're selecting almost an entire worksheet worth of fields and there will be blanks rows included
End With                                                    '1st field done
With objWS.PivotTables(wsName).PivotFields("Agent")       '2nd pivot field selected from data table
    .Caption = "Agent"                                   ' rename field for cleaner look
    .Orientation = xlRowField                               ' this is a row field
    .Position = 2                                           ' this is the 2nd level row field
End With                                                    '2nd field done


With objWS.PivotTables(wsName).PivotFields("Date")      '3rd pivot field selected from data table
    .Orientation = xlColumnField                                        ' this is a column field
End With                                                                'done selecting 3rd field - must now establish value setting

With objWS.PivotTables(wsName).PivotFields("PctAdh")      '3rd pivot field selected from data table
    .Orientation = xlColumnField                                        ' this is a column field
End With  

0 个答案:

没有答案