Renaming object in PPT using VBA

…衆ロ難τιáo~ 提交于 2020-01-17 05:38:07

问题


I am currently trying to do a replace all on the object name in PowerPoint. Normally each content object is named Content Placeholder #, I have already named each object something like "PptBobChart1, PptBobScatter1", and now I need to do a replace all to change each of the object names into "PptTomChart1, PptTomScatter1". I know I can go into the selection pane one at a time to manually change it, but is there a way to do the whole thing in VBA?


回答1:


You could try something like:

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

Hope this Helps!




回答2:


If you want to set different names for different01DEC2015 object types, you can use this:

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


来源:https://stackoverflow.com/questions/34009852/renaming-object-in-ppt-using-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!