无法设置PivotItem类的Visible属性 [英] Unable to set the Visible property of the PivotItem class

查看:2649
本文介绍了无法设置PivotItem类的Visible属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行时错误1004:无法设置PivotItem类的Visible属性。

Run-time error '1004': Unable to set the Visible property of the PivotItem class

Excel中VBA:

Excel VBA:

Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem

Set pf = pt.PivotFields("Snapshot Date")

For Each pi In pf.PivotItems
If pi.Name <> "(blank)" Then
pi = DateValue(pi) 'I have tried using Cdate, Cdbl, Cstr as well.  
End If
Next pi

错误发生在这里:

Errors happen here:

i = 1
Do Until i >= pf.PivotItems.count - 1

For Each pi In pf.PivotItems
pi.Visible = False 'Error here
Next pi

pf.PivotItems(i).Visible = True '.. And here!
pf.PivotItems(i + 1).Visible = True
Loop

枢轴项日期,不知道如果我需要进行格式化之前,我可以打开/关闭的知名度关闭?

The pivot items are dates, not sure if I need to format them before I can turn visibility on/off?

我已经无数次一派,找不到任何解决这个:(一些关于非连续的项目,但我不太明白。

I have googled endlessly and could not find any solution to this :( Something about non-contiguous items, but I don't quite understand.

推荐答案

您必须有至少一个可见PivotItem而你把它们都设无形。您可以通过所有PivotItems需要循环,设置第一个可见= TRUE,然后测试所有的休息,并设置相应的他们,然后测试第一个并进行相应设置。这样,你一定会总有一个可见PivotItem。

You have to have at least one visible PivotItem and you're setting them all to invisible. You need to loop through all the PivotItems, set the first one to visible = True, then test all the rest and set them accordingly, then test the first one and set it accordingly. That way you'll be sure there's always one visible PivotItem.

不过,我真的不知道你的测试是什么。你有一个循环,但不增加的i,所以它会永远循环下去,一直试图设置PivotItems 1和2可见。

However, I'm not really sure what your test is. You have a loop, but don't increment "i", so it will loop forever always trying to set PivotItems 1 and 2 to visible.

我不知道为什么你得到了第二个错误,但如果你能解释一下你想要做什么有可能是一个更好的办法。

I don't know why you're getting that second error, but if you can explain what you're trying to do there may be a better way.

这篇关于无法设置PivotItem类的Visible属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆