Powerpoint: Manually set Slide Name

Cerkvenic picture Cerkvenic · May 31, 2013 · Viewed 31.5k times · Source

Context: A PowerPoint slide in C# has a property Slide.Name (usually contains an arbitrary string value). In my C# application I would like to use this property to identify slides (the slide order is to unreliable).

Question: How can I manually set the Slide.Name property in the PowerPoint Application?

My problem is very like to the: “How to name an object within a PowerPoint slide?” but just on the slide level.

Any help would be appreciated.

Answer

Matthew Kraus picture Matthew Kraus · Jun 9, 2013

There is no built-in functionality in PowerPoint that allows you to edit the name of a slide. As Steve mentioned, you have to do it using VBA code. The slide name will never change due to inserting more slides, and it will stay the same even if you close PowerPoint; the slide name set in VBA code is persistent. Here's some code I wrote to allow you to easily view the name of the currently selected slide and allow you to rename it:

'------------------------------------------------------------------
' NameSlide()
'
' Renames the current slide so you can refer to this slide in
' VBA by name. This is not used as part of the application;
' it is for maintenance and for use only by developers of
' the PowerPoint presentation.
'
' 1. In Normal view, click on the slide you wish to rename
' 2. ALT+F11 to VB Editor
' 3. F5 to run this subroutine
'------------------------------------------------------------------
Sub NameSlide()
    Dim curName As String
    curName = Application.ActiveWindow.View.Slide.name

    Dim newName As String
retry:
    newName = InputBox("Enter the new name for slide '" + curName + "', or press Cancel to keep existing name.", "Rename slide")
    If Trim(newName) = "" Then Exit Sub

    Dim s As Slide

    ' check if this slide name already exists
    On Error GoTo SlideNotFound
    Set s = ActivePresentation.Slides(newName)
    On Error GoTo 0

    MsgBox "Slide with this name already exists!"
    GoTo retry

    Exit Sub

SlideNotFound:
    On Error GoTo 0
    Application.ActiveWindow.View.Slide.name = newName
    MsgBox "Slide renamed to '" + newName + "'."

End Sub