2010-10-23 100 views
3

我想在某種集合,arraylist,
中存儲按鈕,以便我可以動態添加和刪除。vba形狀集合

我試圖使用集合,但似乎它不是選擇,因爲當達到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 

我該如何得到它?

回答

3

ar.Add()未達到arNothing。您應該將其初始化爲New Collection

除此之外,刪除括號:

ar.Add myshape 

隨着括號,您要添加到集合形狀對象的默認屬性的值,並Shape沒有一個默認屬性。

+0

感謝您的幫助,現在它的工作。 – Gadolin 2010-10-23 12:59:12