我目前正在尝试对PowerPoint中的对象名称进行全部替换。通常情况下,每个内容对象都被命名为content Placeholder#,我已经给每个对象命名了类似于"PptBobChart1,PptBobScatter1"的名称,现在我需要进行全部替换,将每个对象名称更改为"PptTomChart1,PPtTomScatter 1"。我知道我可以一次进入一个选择窗格手动更改它,但有没有办法在VBA中完成整个操作?
您可以尝试以下操作:
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
希望这能有所帮助!
如果您想为不同的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