VBA形状的集合 [英] vba collection of shapes

查看:206
本文介绍了VBA形状的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将按钮存储在某种形式的集合,数组列表中,
这样我就可以动态添加和删除.

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

我尝试使用Collection,但似乎不是选择,因为到达ar.Add()时出现错误.

I tried to use Collection but seems it is not the choice, as I got an error when ar.Add() is reached.

对象不支持此属性或方法.

 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().您应该将其初始化为New Collection.

ar.Add() is not reached as ar is Nothing. You should initialize it to a New Collection.

除此之外,删除括号:

ar.Add myshape

要用括号将形状对象的默认属性的值添加到集合中,而Shape没有默认属性.

With the parentheses, you are trying to add to the collection the value of the default property of the shape object, and Shape doesn't have a default property.

这篇关于VBA形状的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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