2015-11-30 23 views
0

我當前正試圖在PowerPoint中對所有的對象名稱進行替換。通常,每個內容對象都被命名爲Content Placeholder#,我已經將每個對象命名爲「PptBobChart1,PptBobScatter1」,現在我需要進行全部替換,以將每個對象名稱更改爲「PptTomChart1,PptTomScatter1」。我知道我可以一次一個地進入選擇窗格來手動更改它,但有沒有辦法在VBA中完成整個工作?使用VBA在PPT中重命名對象

回答

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

如果你想設置different01DEC2015對象類型不同的名稱,您可以使用此:

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