简体   繁体   中英

VBA code for giving slides a constant name

I am trying to reduce the effort needed to keep a certain slide (lets call it SlideXYZ) up to date. SlideXYZ is an important content slide that can be found in multiple slide decks. I initially created slide objects that updated automatically when a change was made in the "source slide". However, slide objects unfortunately don't contain animations (they are simply a snapshot of the actual slide). I am now trying to write a VBA script that will search and replace SlideXYZ in each deck with a newer version of SlideXYZ. However, the slide number is dynamic (it changes when a new slide is added above). I need a static, constant reference to SlideXYZ.

I thought of copying SlideXYZ into all presentations once and then using the Slide.Name property to find all instances of it once an update is needed.

However, it appears that the Slide.Name is reassigned by powerpoint each time the slide is pasted into a new presentation. I need a reference that will not change so that I can find and replace SlideXYZ.

@Asger's suggestion would work but a more consistent approach (IMO) would be to use tags. Any presentation, slide, or shape on a slide can have one or more bits of text attached in the form of a tag.

For example:

ActivePresentation.Slides(1).Tags.Add "SlideIdentifier", "Bob"

will create a tag named SlideIdentifier with a value of Bob on slide #1 in the current presentation. These tags will travel with the slide, wherever it goes.

This page on the PowerPoint FAQ that I maintain has more info on using tags:

http://www.pptfaq.com/FAQ00815_Working_with_Tags_-and_a_bit_about_Functions-.htm

As you already found out: Neither SlideIndex , SlideNumber , SlideID nor Name can be used to identify a copied slide.

You may work with the "alternative text" of a characteristic shape to identify a slide:
Just do a right mouseclick on the shape and edit its alternative text.

Also slide notes may help to identify a slide.

Following prints some slide information to your debug window:

Private Sub IdentifyMySlide()
    Dim myslide As PowerPoint.Slide
    For Each myslide In ActivePresentation.Slides
        Debug.Print "Index: " & myslide.SlideIndex,
        Debug.Print "Number: " & myslide.SlideNumber,
        Debug.Print "ID: " & myslide.SlideID,
        Debug.Print "Name: " & myslide.Name,

        If myslide.Shapes.Count > 0 Then
            Debug.Print "Alternative ShapeText: " & myslide.Shapes(1).AlternativeText,
        End If

        If myslide.HasNotesPage Then
            If myslide.NotesPage(1).Shapes.Count > 0 Then
                If myslide.NotesPage(1).Shapes(1).HasTextFrame Then
                    Debug.Print "Notes: " & Left(myslide.NotesPage(1).Shapes(1).TextFrame.TextRange.Text, 10)
                Else
                    Debug.Print
                End If
            Else
                Debug.Print
            End If
        Else
            Debug.Print
        End If

    Next myslide
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM