简体   繁体   English

VBA代码,用于为幻灯片提供一个常量名称

[英]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)为最新状态所需的精力。 SlideXYZ is an important content slide that can be found in multiple slide decks. SlideXYZ是重要的内容幻灯片,可以在多个幻灯片组中找到。 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. 我现在正在尝试编写一个VBA脚本,该脚本将使用较新版本的SlideXYZ搜索并替换每个卡座中的SlideXYZ。 However, the slide number is dynamic (it changes when a new slide is added above). 但是,幻灯片编号是动态的(在上面添加新幻灯片时,它会更改)。 I need a static, constant reference to SlideXYZ. 我需要对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. 我考虑过一次将SlideXYZ复制到所有演示文稿中,然后在需要更新时使用Slide.Name属性查找其所有实例。

However, it appears that the Slide.Name is reassigned by powerpoint each time the slide is pasted into a new presentation. 但是,每次将幻灯片粘贴到新演示文稿中时,PowerPoint似乎都会重新分配Slide.Name。 I need a reference that will not change so that I can find and replace SlideXYZ. 我需要一个不会更改的参考,以便可以找到并替换SlideXYZ。

@Asger's suggestion would work but a more consistent approach (IMO) would be to use tags. @Asger的建议可以起作用,但是更一致的方法(IMO)是使用标签。 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. 将在当前演示文稿的幻灯片#1上创建一个名为SlideIdentifier的标签,其值为Bob。 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: 我维护的PowerPoint常见问题解答上的此页面包含有关使用标签的更多信息:

http://www.pptfaq.com/FAQ00815_Working_with_Tags_-and_a_bit_about_Functions-.htm 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. 如您SlideIndexSlideIndexSlideNumberSlideIDName都不能用来标识复制的幻灯片。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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