Vba figure collection

I want to store buttons in some kind of collection, arraylist,
so that I can add and remove dynamically.

I tried to use Collection, but it seems that this is not a choice, since I got an error when ar.Add () was reached.

The object does not support this property or method.

 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

How can i get it?

+3
source share
1 answer

ar.Add()not achieved because ar- Nothing. You must initialize it before New Collection.

In addition, remove the parentheses:

ar.Add myshape

In parentheses, you are trying to add the default property value of the shape object to the collection, but Shapedoes not have a default property.

+3
source

Source: https://habr.com/ru/post/1771067/


All Articles