分组形状

时间:2019-02-15 14:03:38

标签: excel vba grouping shapes

我已经根据用户输入创建了三种形状。这三个形状输出看起来像一个卷轴(法兰+鼓)。我希望对形状进行分组,以便用户移动形状时不必分别选择所有三个形状。

在下面的代码中,前三行创建整体形状。最后一行是我未能使这些形状成为一组形状的尝试。

在此问题上提供的任何帮助将不胜感激。谢谢。

Sub AddShapeReel()

Dim s As Shape
Dim s1 As Shape
Dim s2 As Shape
Dim ws As Worksheet
Dim shpgroup
Set ws = Sheets("Deck Layout")

'add a shape

Set s = ws.Shapes.AddShape(msoShapeRectangle, 50, 50, Cells(26, 4) * 2.142857, Cells(28, 4) * 2.142857)
Set s1 = ws.Shapes.AddShape(msoShapeRectangle, 50 - ((Cells(30, 4) * 2.142857 - Cells(26, 4) * 2.142857) / 2), 49, Cells(30, 4) * 2.142857, 1)
Set s2 = ws.Shapes.AddShape(msoShapeRectangle, 50 - ((Cells(30, 4) * 2.142857 - Cells(26, 4) * 2.142857) / 2), Cells(28, 4) * 2.142857 + 50, Cells(30, 4) * 2.142857, 1)
Set shpgroup = ws.Shapes.Range(Array(s, s1, s2)).Group

end sub

1 个答案:

答案 0 :(得分:1)

在创建形状之后,由录制的宏生成的语法看起来像这样:

ActiveSheet.Shapes.Range(Array("Rectangle 2", "Rectangle 3")).Select
Selection.ShapeRange.Group.Select

大概可以通过选择和分组形状来适应这种情况,如下所示:

ActiveSheet.Shapes.Range(Array(s, s1, s2)).Select
Selection.ShapeRange.Group

我还没有机会确认。

相关问题