简体   繁体   English

搜索带有指定标签的幻灯片并将其替换为母版演示文稿中的幻灯片

[英]Searching for a slide with a specified tag and replacing it with a slide from a master presentation

I am looking to search a presentation for a slide or slides that have a specified tag.我希望在演示文稿中搜索具有指定标签的一张或多张幻灯片。 Once found, I would like to replace the slide with another slide from a master presentation.找到后,我想用主演示文稿中的另一张幻灯片替换该幻灯片。

I have attempted to create a solution with parts of other VBA I have collected.我试图用我收集的其他 VBA 的部分内容创建一个解决方案。 I sense I am close but am not there yet (note the below gets me stuck in a loop).我感觉我很接近但还没有到那里(注意下面让我陷入循环)。

Any help would be gratefully received任何帮助将不胜感激

Sub ReplaceSlideThatHasTag()


For Each osld In ActivePresentation.Slides

'here I am selecting the slide that has the tag name "winter" and the tag id "123
If osld.Tags("WINTER") = "123" Then osld.Select

'here I am trying to add slide 27 from my master presentation immediately before the slide with the tag
ActivePresentation.Slides.InsertFromFile ("C:\my files\master presentation.PPTX"), ActiveWindow.Selection.SlideRange.SlideIndex, 24, 24

'and finally I am looking to delete the slide with the tag
If osld.Tags("WINTER") = "123" Then osld.Delete


Next osld

End Sub

A bit of general advice: Never select anything unless you can't avoid it, and it's almost never the case that you can't avoid it.一些一般性建议:永远不要选择任何东西,除非你无法避免它,而且几乎从来没有你无法避免它的情况。 Suggestions (with commments) below.建议(带评论)如下。 Give this version a try.试试这个版本。

Sub ReplaceSlideThatHasTag()

' ALWAYS dim your variables before using them
Dim osld as Slide

For Each osld In ActivePresentation.Slides

'here I am selecting the slide that has the tag name "winter" and the tag id "123

If osld.Tags("WINTER") = "123" Then '  DON'T select anythin osld.Select

'here I am trying to add slide 27 from my master presentation immediately before the slide with the tag
'ActivePresentation.Slides.InsertFromFile ("C:\my files\master presentation.PPTX"), 'ActiveWindow.Selection.SlideRange.SlideIndex, 24, 24

' But since we're not selecting anything ...
ActivePresentation.Slides.InsertFromFile ("C:\my files\master presentation.PPTX"), _ osld.SlideIndex

'and finally I am looking to delete the slide with the tag
' But we already have a reference to the slide in the osld variable
' and we know that the slide has the tag so ...
'If osld.Tags("WINTER") = "123" Then osld.Delete
osld.Delete

' And since we've found the slide and done the deed,
' no need to continue...
Exit For
End If
Next osld

End Sub

暂无
暂无

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

相关问题 在 PowerPoint 演示文稿中复制幻灯片 - Duplicating a slide in PowerPoint presentation 将布局应用到来自特定母版的幻灯片 - Applying layout to a slide from specific Master 从Access VBA打开PowerPoint演示文稿的特定幻灯片 - open particular slide of powerpoint presentation from access vba 通过 VBA 获取 PPT 演示文稿的活动幻灯片(但来自 Excel !!) - Getting the Active Slide of a PPT Presentation via VBA (but from Excel!!) 将一张幻灯片复制到多个演示文稿 - Copy one slide to multiple presentation 从Excel调用宏以打开PowerPoint演示文稿,插入幻灯片以及将范围复制到幻灯片有时会起作用,但会出错 - Macro called from Excel to Open a PowerPoint Presentation, Insert a Slide, and Copy Range to Slide works sometimes, errors others 粘贴到母版幻灯片中 - Pasting into the Master slide 在另一个 Powerpoint 演示文稿中嵌入来自其他 Powerpoint 演示文稿的幻灯片的链接副本 - Embed a linked copy of a slide from other Powerpoint presentation in another Powerpoint presentation 如何根据特定的幻灯片输入将幻灯片从现有演示文稿复制到新演示文稿? - How to copy the slides from existing presentation to new presentation based on the specific slide input? 是否可以检查一个PowerPoint演示文稿中的幻灯片是否与另一个套牌中的幻灯片相同? - Is it possible to check if a slide in one PowerPoint presentation is the same as a slide in another deck?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM