形状名称PPT VBA

Shape names PPT VBA

我想在 PPT 中按索引引用形状 VBA。它正在工作,但它很受欢迎,因为我正在将它们剪切并粘贴到不同的幻灯片,因此索引不断变化。有没有另一种方法来引用形状,这样我就不必处理索引了?这是我的代码示例:

ActivePresentation.Slides(1).Shapes(3).Cut
ActivePresentation.Slides(2).Shapes.Paste
ActivePresentation.Slides(1).Shapes(4).Cut
ActivePresentation.Slides(2).Shapes.Paste

 With ActivePresentation.Slides(1).Shapes(3)
.Height = 325
.Width = 325
.Left = 190
.Top = 90

End With

With ActivePresentation.Slides(1).Shapes(4)
.Height = 600
.Width = 600
.Left = 65
.Top = 360

End With

在剪切前标记形状,然后调用函数return粘贴后目标幻灯片中用该值标记的形状:

With ActivePresentation.Slides(1).Shapes(3)
  .Tags.Add "SomeName", "SomeValue" 
  ' whatever name and value you like
  .Cut
End With

' Then paste it onto another slide
' and to get a reference to it:

Dim oSh as shape
Set oSh = ShapeTaggedWith(oSl, "SomeName", "SomeValue")
If Not oSh is Nothing Then

End If
' etc

Function ShapeTaggedWith(oSl as Slide, sTagName as String sValue as String) as Shape
   Dim oSh as Shape
   For each oSh in oSl.Shapes
      If oSh.Tags(sTagName) = sValue Then
          Set ShapeTaggedWith = oSh
          Exit Function
      End If
   Next

End Function