CalculatedMembers![]() |
代表数据透视表的计算字段和计算项,该数据透视表以联机分析处理 (OLAP) 为数据源。
可用 Add 方法或 CalculatedMembers 集合的 Item 属性返回一个 CalculatedMember 对象。
可用 CalculatedMember 对象的 IsValid 属性检查数据透视表中计算字段或计算项的有效性。
注意 如果数据透视表当前没有连接到数据源,IsValid 属性将返回 True。在测试 IsValid 属性之前请使用 MakeConnection 方法。
下例通知用户计算成员是否有效。本示例假定活动工作表中存在数据透视表,该活动工作表中包含有效或无效的计算成员。
Sub CheckValidity()
Dim pvtTable As PivotTable
Dim pvtCache As PivotCache
Set pvtTable = ActiveSheet.PivotTables(1)
Set pvtCache = Application.ActiveWorkbook.PivotCaches.Item(1)
' Handle run-time error if external source is not an OLEDB data source.
On Error GoTo Not_OLEDB
' Check connection setting and make connection if necessary.
If pvtCache.IsConnected = False Then
pvtCache.MakeConnection
End If
' Check if calculated member is valid.
If pvtTable.CalculatedMembers.Item(1).IsValid = True Then
MsgBox "The calculated member is valid."
Else
MsgBox "The calculated member is not valid."
End If
End Sub