Excel VBA – 设置PivotItems错误的可见性

我使用下面的代码来过滤Excel中的数据透视表(但是从PowerPoint中) – 我设法清除“date”字段的filter,但是我无法设置oPi值的可见性。

 Sub Data() Dim oExcel As Excel.Application Dim oWB As Workbook Dim oPi As PivotItem Set oExcel = New Excel.Application oExcel.Workbooks.Open ("\\A79APBRSFACTD\MDSS\FactivityServer\FactShar\OEE_Daily2.xls") oExcel.Visible = True Set oExcel = Excel.Application Set oWB = oExcel.Workbooks("OEE_Daily2.xls") oWB.Sheets("OEE Pivot Daily").Select oExcel.Run ("Update_OEE_Daily") oWB.Sheets("OEE Pivot Daily").Range("B3").Select oWB.Sheets("OEE Pivot Daily").PivotTables("PivotTable2").PivotFields("Date").Orientation = xlHidden With oWB.Sheets("OEE Pivot Daily").PivotTables("PivotTable2").PivotFields("Date") .Orientation = xlPageField .Position = 1 .ClearAllFilters For Each oPi In .PivotItems If oPi.Value <> "7/1/2013" Then oPi.Visible = False 'Offending Line End If Next oPi End With Set oExcel = Nothing Set oWB = Nothing End Sub 

我收到的错误是Run-time error '1004': unable to set the visible property of the PivotItem该行Run-time error '1004': unable to set the visible property of the PivotItem oPi.Visible = False

我已经添加了oPi.ValueoPi.Visible的手表,并通过代码 – 行被卡在设置oPi.Value = 4/26/2013的知名度,我发现,当我hover在线上,我请参阅oPi.Visible = <Type Mismatch> ,如下所示:

oPi.Visible = <类型不匹配>

False的地方,我尝试了使用0CBool(0) ,但都无济于事! 任何帮助解决这个问题,并允许可见性被改变,将不胜感激!