微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我希望在演示文稿中搜索具有指定标签的一张或多张幻灯片。找到后,我想用母版演示文稿中的另一张幻灯片替换该幻灯片

我试图用我收集的其他 VBA 的部分内容创建一个解决方案。我感觉我很接近但还没有到那里(注意下面让我陷入循环)。

如有任何帮助,我们将不胜感激

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

解决方法

一些一般性建议:永远不要选择任何东西,除非您无法避免它,而且几乎从来没有您无法避免它的情况。建议(带评论)如下。试试这个版本。

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。