使用VBA重命名PPT中的对象

问题描述 投票:0回答:2

我目前正在尝试在PowerPoint中的对象名称上全部替换。通常每个内容对象都被命名为Content Placeholder#,我已经将每个对象命名为“ PptBobChart1,PptBobScatter1”,现在我需要做一个替换操作,将每个对象名称更改为“ PptTomChart1,PptTomScatter1”。我知道我可以一次进入选择窗格以手动更改它,但是有没有办法在VBA中完成全部操作?

vba powerpoint powerpoint-vba
2个回答
0
投票

您可以尝试以下方法:

Sub renameObj()
    Dim o As Shape
    Dim s As Slide
    For Each s In ActivePresentation.Slides
        For Each o In s.Shapes
            o.Name = Replace(o.Name, "Bob", "Tom")
        Next o
    Next s
End Sub

希望有帮助!


0
投票

如果要为不同的01DEC2015对象类型设置不同的名称,则可以使用此:

Option Explicit

' ============================================================
' PowerPoint Macro : RenameOnSlideObjects
' ============================================================
' Purpose : Renames all on-slide objects within a presentation
' Inputs : Noe
' Outputs : None
' Dependencies : None
' Author : Jamie Garroch of http://youpresent.co.uk/
' Date : 01 December 2015
' ============================================================
Public Sub RenameOnSlideObjects()
  Dim oSld As Slide
  Dim oShp As Shape
  For Each oSld In ActivePresentation.Slides
    For Each oShp In oSld.Shapes
      With oShp
        Select Case True
          Case .Type = msoPlaceholder ' you could then check the placeholder type too
            .Name = "myPlaceholder"
          Case .Type = msoTextBox
            .Name = "myTextBox"
          Case .Type = msoAutoShape
            .Name = "myShape"
          Case .Type = msoChart
            .Name = "myChart"
          Case .Type = msoTable
            .Name = "myTable"
          Case .Type = msoPicture
            .Name = "myPicture"
          Case .Type = msoSmartArt
            .Name = "mySmartArt"
          Case .Type = msoGroup ' you could then cycle though each shape in the group
            .Name = "myGroup"
         Case Else
            .Name = "Unspecified Object"
        End Select
      End With
    Next
  Next
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.