据我所知,下面的代码从活动窗口获取一个形状,轻轻一点,复制幻灯片并将其粘贴到当前窗口之后,然后将粘贴的幻灯片转换为活动窗口,并轻推它再次:
子测试()
' Get the active presentation Dim oPresentation As Presentation Set oPresentation = ActivePresentation ' Get the first slide in the presentation Dim oSlide As Slide Set oSlide = oPresentation.Slides(1) ' Get the first shape on the slide Dim oShape As Shape Set oShape = oSlide.Shapes(1) ' Nudge the shape to the right oShape.Left = oShape.Left + 1 ' Copy the whole slide oSlide.Copy ' Paste the slide as a new slide at position 2 Dim oNewSlides As SlideRange Set oNewSlides = oPresentation.Slides.Paste(2) ' Get a reference to the slide we pasted Dim oNewSlide As Slide Set oNewSlide = oNewSlides(1) ' Get the first shape on the NEW slide Dim oNewShape As Shape Set oNewShape = oNewSlide.Shapes(1) ' Nudge the shape to the right oNewShape.Left = oNewShape.Left + 1
End Sub
据我所知,为了实现这个代码,我应该打开一个活动窗口,它应该至少有一个形状。在我运行此代码之前,我只有一张幻灯片;代码运行后,我有两张幻灯片:较旧的一张是1号,而较新的号码是2号。
如果我再次运行此代码,我会得到三张幻灯片:最旧的一张仍然是1号,但最旧的号码是2号,而不是3号。
我的问题是如何让它制作幻灯片,以便新的幻灯片总是具有更大序数的幻灯片,即每个新创建的幻灯片应该是幻灯片预览侧边栏中的最后一个(最低的幻灯片)?
而且,我怎样才能把它变成循环?因此,我不需要一次又一次地重新运行此代码,而只需使用给定数量的循环迭代进行循环。
我想,如果它应该是一个循环,那么幻灯片索引应该变成一个变量,但我不知道如何在PowerPoint VBA中这样做。
答案 0 :(得分:4)
我不确定你的代码是否有意义。它本质上是:
为什么它会移动两次,一次放在原件上,一次放在复印件上?
无论回答您的具体问题:
要将其粘贴为最后一张幻灯片,请替换
Set oNewSlides = oPresentation.Slides.Paste(2)
使用
Set oNewSlides = oPresentation.Slides.Paste() #no index pastes as last
循环使用这样的东西:
Dim oPresentation As Presentation
Set oPresentation = ActivePresentation
Dim oSlide As Slide
Dim oSlides As SlideRange
Dim oShape As Shape
Dim slideNumber As Integer
For slideNumber = 1 To 10
Set oSlide = oPresentation.Slides(oPresentation.Slides.Count)
oSlide.Copy
Set oNewSlides = oPresentation.Slides.Paste()
Set oSlide = oNewSlides(1)
Set oShape = oSlide.Shapes(1)
oShape.Left = oShape.Left + 5
Next slideNumber
这将拍摄最后一张幻灯片,复制它,将副本粘贴为新的最后一张,向右轻推第一张形状,拍摄新的最后一张幻灯片,复制它,将副本粘贴为最后一张,将第一张形状轻推到正确等等......它会做10次。