问题描述
我正在遍历电气表"表上的数据,并在形状"表上创建形状.创建形状后,我想以编程方式对它们进行分组.但是我找不到正确的语法.形状在那里,被选中,如果我单击分组"按钮,它们将完美分组.但是,使用以下代码,我得到
I am iterating over data on the Electrical Tables sheet and creating shapes on a Shape sheet. Once the shapes are created I would like to programmatically group them. However I can't figure out the right syntax. The shapes are there, selected, and if I click the group button, they group perfectly. However with the following code I get
我将这些代码基于Web上的VBA示例-我不是一个强大的VBA程序员.什么是正确的方法?我正在使用excel 2007,并且无法切换excel版本.
I am basing this code on VBA examples off the web - I am not a strong VBA programmer. What is the right way to do this? I am working with excel 2007 and switching excel versions isn't an option.
问题摘要:
Set shapeSheet = Worksheets("Shapes")
With shapeSheet
Selection.ShapeRange.Group.Select
End With
上下文:
Dim shapeSheet As Worksheet
Dim tableSheet As Worksheet
Dim shpGroup As Shape
Set shapeSheet = Worksheets("Shapes")
Set tableSheet = Worksheets("Electrical Tables")
With tableSheet
For Each oRow In Selection.Rows
rowCount = rowCount + 1
Set box1 = shapeSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 50, 50 + ((rowCount - 1) * 14), 115, 14)
box1.Select (False)
Set box1Frame = box1.TextFrame
Set box2 = shapeSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 165, 50 + ((rowCount - 1) * 14), 40, 14)
box2.Select (False)
Set box2Frame = box2.TextFrame
Next
End With
Set shapeSheet = Worksheets("Shapes")
With shapeSheet
Selection.ShapeRange.Group.Select
End With
推荐答案
这在Excel 2010中对我有用:
This worked for me in Excel 2010:
Sub GroupShapes()
Sheet1.Shapes.SelectAll
Selection.Group
End Sub
我在工作表1上有两个形状,在调用上述方法之前未进行分组,而在之后进行了分组.
I had two shapes on sheet 1 which were ungrouped before calling the method above, and grouped after.
要使用索引选择特定形状:
To select specific shapes using indexes:
Sheet1.Shapes.Range(Array(1, 2, 3)).Select
使用名称:
Sheet1.Shapes.Range(Array("Oval 1", "Oval 2", "Oval 3")).Select
这篇关于如何在excel 2007 vba中以编程方式对一组形状进行分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!