简体   繁体   English

VBA Powerpoint:循环并重命名所有幻灯片

[英]VBA Powerpoint: loop through and rename all the slides

I am looking to rename all the slides in several presentations so that I can easily identify them.我希望重命名几个演示文稿中的所有幻灯片,以便我可以轻松识别它们。 I will use them to build other presentations and need a way to identify if a slide came from a certain previous presentation.我将使用它们来构建其他演示文稿,并且需要一种方法来识别幻灯片是否来自某个先​​前的演示文稿。 When I try to cycle through the slides, I get a read-only error when trying to rename the slide.当我尝试循环浏览幻灯片时,在尝试重命名幻灯片时出现只读错误。 How do I access and set the name?如何访问和设置名称? the sub fails when I try to change the 'name' property.当我尝试更改“名称”属性时,sub 失败。 Many thanks!非常感谢!

Sub EverySlideInPresentation1234(oPres As Presentation) ' Performs some operation on every slide in the currently active presentation Sub EverySlideInPresentation1234(oPres As Presentation) ' 对当前活动演示文稿中的每张幻灯片执行一些操作

Dim oSl As slide

For Each oSl In oPres.Slides


    oSl.Name = (("updatePort: " & Now()))

Next oSl

End Sub结束子

I was able to repro this.我能够重现这个。 The problem is that Now() returns date + hh:mm:ss AM|PM but there's way less than one second between the time you rename the first slide and the next, so you end up giving ... trying to give ... multiple slides the same name.问题是 Now() 返回 date + hh:mm:ss AM|PM 但是在您重命名第一张幻灯片和下一张幻灯片之间的时间不到一秒钟,所以您最终放弃...试图放弃 .. . 多张同名幻灯片。 PowerPoint doesn't allow that. PowerPoint 不允许这样做。

Use something like this to make the slide name unique:使用这样的东西来使幻灯片名称唯一:

oSl.Name = (("updatePort: " & Now())) & " " & oSl.SlideIndex

Or use Tags to store the data on the slide itself rather than using the name.或者使用标签将数据存储在幻灯片本身上,而不是使用名称。 Each slide could have a tag with the same value:每张幻灯片都可以有一个具有相同值的标签:

oSl.Tags.Add "UpdateTag", "updatePort: " & Now()

There's more info about using Tags on a PowerPoint FAQ site that I maintain, here:在我维护的 PowerPoint 常见问题网站上有更多关于使用标签的信息,在这里:

Working with Tags (and a bit about Functions) 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

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

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