本文介绍了在多个打开的演示文稿中替换一张幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我拼凑了一些 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
这篇关于在多个打开的演示文稿中替换一张幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!