Skip to content

How to name an object in PowerPoint using VBA


Sub AssignName()

  Dim name As String

  With ActiveWindow.Selection.ShapeRange(1)
    name = InputBox("New name:", "Rename Object", .Name)
    Select Case name
     Case Is = ""
       Exit Sub
     Case Else
       On Error Resume Next
       .Name = name
       If Err.Number <> 0 Then
         MsgBox "Cannot rename object"
       End If
    End Select
  End With

End Sub

An easy way to name objects in a PowerPoint file, which is pretty much a necessity of you want to be able to use automation to manipulate the objects in a preentation, is to use a dedicated function in you presentation to do so.

  • Open the Powerpoint file that you need automated
  • From the Menu Toolbar choose Tools | Macros | Visual Basic Editor
  • Copy the following code into the resulting VBA editor screen
  • Now save
  • Select the object that you want to rename
  • From the Menu Toolbar choose Tools | Macros | Macro
  • Select the macro AssignName
  • Click the Run button
  • Type the new name for the object
  • Click OK
4
Your rating: None Average: 4 (1 vote)
AdaptiveThemes