我想将按钮存储在某种集合中,数组列表,
这样我就可以动态添加和删除。
我尝试使用 Collection,但似乎这不是选择,因为当到达 ar.Add() 时我收到错误。
对象不支持此属性或方法。
Public Sub removeAllFormsWithAdd()
Dim myshape As Shape
Dim ar As Collection
For Each myshape In ActiveSheet.Shapes
If (myshape.FormControlType = xlButtonControl) Then
If (myshape.TextFrame.Characters.Text = "name") Then
ar.Add (myshape)
Debug.Print "next shape:" & myshape.TextFrame.Characters.Text & "-"
End If
End If
Next myshape
End Sub
我怎样才能得到它?
最佳答案
未达到
ar.Add()
,因为 ar
为 Nothing
。您应该将其初始化为新集合
。
除此之外,删除括号:
ar.Add myshape
使用括号,您试图将 shape 对象的默认属性值添加到集合中,而 Shape
没有默认属性。
关于VBA 形状集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4004004/