应用于 PivotCache 对象的 SourceDataFile 属性。
应用于 QueryTable 对象中的 SourceDataFile 属性。
对于基于文件的数据源(如 Access),SourceDataFile 属性包括一个指向源数据文件的完整路径。对于基于服务器的数据源(如 SQL Server),该属性为空。如果以程序方式更改 Connection 属性,则 SourceDataFile 属性为空。
本示例确定是否存在与缓存相连的连接,如果存在,则显示数据源文件的名称。如果不存在该连接,代码将处理运行错误,并通知用户。本示例假定数据透视表位于活动工作表上。
Sub CheckSourceConnection()
Dim pvtCache As PivotCache
Set pvtCache = Application.ActiveWorkbook.PivotCaches.Item(1)
On Error GoTo No_Connection
MsgBox "The data source connection is: " & _
pvtCache.SourceDataFile
Exit Sub
No_Connection:
MsgBox "PivotCache source cannot be determined."
End Sub