在多个打开的演示文稿中替换一张幻灯片

编程入门 行业动态 更新时间:2024-10-11 01:09:51
本文介绍了在多个打开的演示文稿中替换一张幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我拼凑了一些 VBA 代码,希望能在几个公开的演示文稿中替换一张相同的幻灯片.

I cobbled together some VBA code in the hopes of replacing a single, identical slide in several open presentations.

这将新幻灯片粘贴到末尾而不是旧幻灯片被删除的位置.另外,我需要在所有打开的演示文稿中发生这种情况.请注意,我通过 SlideID 识别幻灯片.

This pasted the new slide at the end rather than where the old slide was deleted. Also, I'd need this to happen with all open presentations. Note that I identify slides by SlideID.

Sub ReplaceOneSlide() ActivePresentation.Slides.FindBySlideID(1846).Delete Dim sourcePresentation As Presentation On Error Resume Next Set sourcePresentation = Application.Presentations("X:\Marketing Presentations (Final) \Slide Library\Slide Library.pptm") 'change the name accordingly If sourcePresentation Is Nothing Then MsgBox "Source presentation not found!", vbExclamation Exit Sub End If On Error GoTo 0 Dim vSlideIDs As Variant vSlideIDs = Array(1846) 'change the slide IDs accordingly Dim i As Long For i = LBound(vSlideIDs) To UBound(vSlideIDs) sourcePresentation.Slides.FindBySlideID(vSlideIDs(i)).Copy ActivePresentation.Slides.Paste Next i End Sub

推荐答案

为什么要使用数组来保存一个值?

Why are you using an array to hold one value?

Dim vSlideIDs As Variant vSlideIDs = Array(1846) 'change the slide IDs accordingly Dim i As Long For i = LBound(vSlideIDs) To UBound(vSlideIDs) sourcePresentation.Slides.FindBySlideID(vSlideIDs(i)).Copy ActivePresentation.Slides.Paste Next i

相反,试试这样的(主要是空气)代码:

Instead try something like this (largely air)code:

Dim lSlideIDs As Long Dim oSld as Slide Dim lIndex as long lSlideIDs = 1846 'change the slide IDs accordingly lIndex = sourcePresentation.Slides.FindBySlideID(lSlideIDs).SlideIndex sourcePresentation.Slides.FindBySlideID(lSlideIDs).Copy ActivePresentation.Slides.Paste Set oSld = ActivePresentation.Slides(ActivePresentation.Slides.Count) oSld.MoveTo lIndex 'Next i ' commenting this out, per OP's comment; my bad

更多推荐

在多个打开的演示文稿中替换一张幻灯片

本文发布于:2023-10-31 10:42:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545840.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   幻灯片   演示文稿

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!