1

我正在使用以下代码在 excel 中过滤数据透视表(但来自 powerpoint) - 我设法清除了“日期”字段的过滤器,但在设置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针对该行的oPi.Visible = False

我已经添加了一个手表oPi.ValueoPi.Visible逐步执行了代码 - 该行在设置可见性时卡住了oPi.Value = 4/26/2013,我发现当我将鼠标悬停在该行上时,我看到oPi.Visible = <Type Mismatch>如下:

oPi.Visible = <类型不匹配>

代替False, 我曾尝试使用0, 和CBool(0),但都无济于事!对于解决此问题并允许更改可见性的任何帮助,将不胜感激!

4

0 回答 0