无法通过Shape.Name =连接形状

时间:2017-07-27 18:13:24

标签: excel vba excel-vba

我想使用以下代码在Excel中使用连接器连接不同的形状:

Set Shape = w.Shapes.AddShape(msoShapeRectangle, X, Y, w, h) With Shape .Name = ExampleName+i End With

出于某种原因,我只能通过Shape添加连接器,但不能通过ExampleName+i添加连接器。

conn.ConnectorFormat.BeginConnect Shape, 1< - 工作 `conn.ConnectorFormat.BeginConnect ExampleName + i,1< - 不起作用

有任何建议如何解决这个问题?我需要这个,因为形状是在For循环中创建的,并且意味着有不同的名称。

1 个答案:

答案 0 :(得分:0)

当您处于For循环中时,只要您一次只使用一个形状,就可以将创建形状称为您设置的任何形状。在这种情况下Shape(我会改变这个变量)。

所以循环看起来像:

Sub test()
For each strName in strNames()
    Set shpRectangle = w.Shapes.AddShape(msoShapeRectangle, X, Y, w, h)
    With shpRectangle
        .Name = strName
    End With
    shpRectangle.       <rest of code>
Next strName
End Sub