IsConnected 属性

       

如果 MaintainConnection 属性为 True 并且数据透视表缓存当前与其源相连,则返回 True。如果数据透视表缓存当前未与其源相连,则返回 FalseBoolean 类型,只读。

expression.IsConnected

expression   必需。该表达式返回一个 PivotCache 对象。

说明

IsConnected 属性不检查是否建立了连接。即使该属性返回 True,如果连接不再有效,那么向提供程序发送命令也将导致错误。

要求缓存的源类型是外部的,并且是一个 OLE DB 数据源。

示例

下例确定缓存是否与其源相连,并通知用户。本示例假定数据透视表位于活动工作表上。

Sub CheckIsConnected()

    ' Handle run-time error if external source is not an OLEDB.
    On Error GoTo Not_OLEDB

    ' Check connection setting and notify the user accordingly.
    If Application.ActiveWorkbook.PivotCaches.Item(1).IsConnected = True Then
        MsgBox "The PivotCache is currently connected to its source."
    Else
        MsgBox "The PivotCache is not currently connected to its source."
    End If
    Exit Sub

Not_OLEDB:
    MsgBox "The data source is not an OLEDB data source."

End Sub