VBA Excel:无效的属性

.Caption =我得到错误“Invalid property”。 任何想法为什么? TabData是我的用户名称,HiddenLabel是我的标签名称。 RList()是一个数组,我试图索引查找最大的元素。 谢谢您的帮助!

  For l = 1 To R_win Set TabData.HiddenLabel.Caption = RList(l).Value w = HiddenLabel.Width If w > m Then m = w End If Next l 

如果Rlist()是一个数组,然后使用:

 TabData.HiddenLabel.Caption = Cstr(RList(l)) '<-- CStr() function converts the array content into a string 

否则告诉我们什么Rlist()是…

您不Set标题属性。 这是一个string,而不是一个对象。 你需要这样做:

 Dim obj As Variant Set obj = TabData.HiddenLabel obj.Caption = RList(l).Value 

或者只是省略Set关键字并使用:

 TabData.HiddenLabel.Caption = RList(l).Value