PowerPoint VBA分组用于选定的形状
我正在尝试创建一个子进程,该过程创建一堆图像并多次对其进行分组。 对于第一个循环,一切运行正常,VBA代码按预期运行,第二次运行VBA会出现错误“分组为选定形状禁用”
Sub PPT_AddShape14
x = 8 * (i - 1) + 170 * (i - 1)
y = 0
Set sh1 = vslide.Shapes.AddShape(msoShapeRectangle, x + 8, y + 8, 170, 170)
Set sh2 = vslide.Shapes.AddShape(msoShapeRectangle, x + 8, y + 178, 170, 30)
Set sh3 = vslide.Shapes.AddShape(msoShapeRectangle, x + 8, y + 208, 170, 190)
vslide.Shapes.Range(Array("sh1", "sh2", "sh3")).Group.Name = Str(x)
Set Tiles = vslide.Shapes(Str(x))
End Sub
I am trying to create a Sub process which create a bunch of image and group it multiple times.
For First loop everything runs OK VBA Code runs as expected, On Second run VBA gives the error "Grouping is disable for selected shapes"
Sub PPT_AddShape14
x = 8 * (i - 1) + 170 * (i - 1)
y = 0
Set sh1 = vslide.Shapes.AddShape(msoShapeRectangle, x + 8, y + 8, 170, 170)
Set sh2 = vslide.Shapes.AddShape(msoShapeRectangle, x + 8, y + 178, 170, 30)
Set sh3 = vslide.Shapes.AddShape(msoShapeRectangle, x + 8, y + 208, 170, 190)
vslide.Shapes.Range(Array("sh1", "sh2", "sh3")).Group.Name = Str(x)
Set Tiles = vslide.Shapes(Str(x))
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将选项显式放在每个模块的顶部并正确声明您的变量总是一个好主意。但是您的代码问题是,范围将形状的名称作为参数,而不是恰好与您给出的对象变量匹配的字符串。这有效:
It's always a good idea to put Option Explicit at the top of every module and to properly declare your variables. But the issue with your code is that Range takes the NAMES of shapes as arguments, not strings that happen to match the names you've given the object variables you're using. This works: