Powerpoint VBA 已对所选形状禁用分组
Powerpoint VBA Grouping is disabled for the selected shapes
我正在尝试创建一个子进程来创建一堆图像并将其分组多次。
对于 First loop everything 运行s OK VBA Code 运行s as expected,在 Second 运行 VBA 给出错误“Grouping is disable for selected shapes”。 =12=]
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
将 Option Explicit 放在每个模块的顶部并正确声明变量始终是个好主意。但是您的代码的问题是 Range 将形状的名称作为参数,而不是恰好与您为正在使用的对象变量提供的名称相匹配的字符串。这有效:
Option Explicit
Sub PPT_AddShape14()
Dim i As Long
Dim x As Long
Dim y As Long
Dim sh1 As Shape
Dim sh2 As Shape
Dim sh3 As Shape
Dim vslide As Slide
Set vslide = ActivePresentation.Slides(1) ' as test
Dim Tiles As Shape
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.Name, sh2.Name, sh3.Name)).Group.Name = Str(x)
Set Tiles = vslide.Shapes(Str(x))
End Sub
我正在尝试创建一个子进程来创建一堆图像并将其分组多次。 对于 First loop everything 运行s OK VBA Code 运行s as expected,在 Second 运行 VBA 给出错误“Grouping is disable for selected shapes”。 =12=]
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
将 Option Explicit 放在每个模块的顶部并正确声明变量始终是个好主意。但是您的代码的问题是 Range 将形状的名称作为参数,而不是恰好与您为正在使用的对象变量提供的名称相匹配的字符串。这有效:
Option Explicit
Sub PPT_AddShape14()
Dim i As Long
Dim x As Long
Dim y As Long
Dim sh1 As Shape
Dim sh2 As Shape
Dim sh3 As Shape
Dim vslide As Slide
Set vslide = ActivePresentation.Slides(1) ' as test
Dim Tiles As Shape
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.Name, sh2.Name, sh3.Name)).Group.Name = Str(x)
Set Tiles = vslide.Shapes(Str(x))
End Sub