本文介绍了为什么这个PivotItem.Visible调用抛出一个TypeMismatch错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是令我们感到困惑的。我有一个标准的透视表,其中包含报表过滤器,允许多个项目选择。我可以在报表过滤器中获取所选项目:

  Dim pi As PivotItem 
对于每个pi在数据透视表MyPivot)。PivotFields(MyField)。PivotItems
如果pi.Visible Then
Debug.Print pi.Value
End If
Next

简单。我的collegue有一个标准的透视表,其上有一个报告过滤器,允许多个项目选择。他尝试使用相同的代码

在报表过滤器中获取所选项目:

  Dim pi As PivotItem 
对于每个pi在数据透视表(HisPivot)。PivotFields(HisField)。PivotItems
如果pi.Visible then
Debug.Print pi.Value
End If
下一个

并在 pi.Visible 。我们知道,可见 pi 中的一个属性,就像在输入 pi之后一样。 intellisense将显示所有的 PivotItem 属性和方法(如您所料)。我们知道pi包含有效的PivotItem,因为调用 pi.Value 正确打印值(删除如果 / End If 语句只是让它打印值,无论打印列表中的每个项目)。他的报告过滤器没有什么特殊 - 它不是计算的字段或任何类似的。大多数其他属性 PivotItem 也失败。



有谁知道为什么 PivotItem 会显示这个行为? 似乎相当不足。

解决方案

我的同事在:

我不会假装理解大多数,或者为什么格式应该对PivotItem属性有任何影响,但它已经有效。我们的解决方案与详细的答案略有不同:他的报告过滤器的日期格式为 * dd / mm / yyyy 。将其更改为 dd / mm / yyyy 可以解决问题。完全令人困惑。


This is baffling us. I have a standard pivot table with a report filter on it that allows multiple selection of items. I can get the selected items in the report filter with:

Dim pi As PivotItem
For Each pi In PivotTables("MyPivot").PivotFields("MyField").PivotItems
    If pi.Visible Then
        Debug.Print pi.Value
    End If
Next

Simple. My collegue has a standard pivot table with a report filter on it that allows multiple selection of items. He tries getting selected items in the report filter with the same code:

Dim pi As PivotItem
For Each pi In PivotTables("HisPivot").PivotFields("HisField").PivotItems
    If pi.Visible Then
        Debug.Print pi.Value
    End If
Next

And gets a Type Mismatch error on pi.Visible. We know that Visible is a property in pi, as after typing pi. the intellisense appears with all the PivotItem properties and methods (as you'd expect). We know that pi contains a valid PivotItem, as calling pi.Value prints the value correctly (removing the If/End If statements to just let it print the value regardless will print every item in the list). There is nothing 'special' about his report filter - it isn't a calculated field or anything like that. Most other properties of PivotItem also fail.

Does anyone know why PivotItem would show this behaviour? The MSDN reference seems rather inadequate.

解决方案

My collegue found the answer after much Googling in this post:

I'm not going to pretend to understand most of that or why the format should have any effect at all on PivotItem properties, but it has worked. Our solution was slightly different to the answer detailed there: his report filter had the date format *dd/mm/yyyy. Changing it to dd/mm/yyyy fixed the issue. Totally baffling.

这篇关于为什么这个PivotItem.Visible调用抛出一个TypeMismatch错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 06:39