【发布时间】:2010-12-15 02:44:53
【问题描述】:
据我所知,下面的代码从活动窗口中获取了一个形状,稍微微调它,复制幻灯片并将其粘贴到当前幻灯片之后,然后将粘贴的幻灯片变成活动窗口,然后微调它再次:
子测试()
' 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结束子
据我所知,为了实现这段代码,我应该打开一个活动窗口,并且它应该至少有一个形状。在我运行这段代码之前,我只有一张幻灯片;代码运行后,我有两张幻灯片:旧的一张是 1 号,新的一张是 2 号。
如果我再次运行此代码,我将得到三张幻灯片:最旧的仍然是 1 号,但最旧的一张是 2 号,而不是 3 号。
我的问题是如何让它生成幻灯片,以便新的幻灯片总是具有更大序号的幻灯片,即每张新创建的幻灯片都应该是幻灯片预览侧栏中的最后一张(最低的一张)?
还有,我怎样才能让它变成一个循环?这样我就不需要一次又一次地重新运行这段代码,而只需使用给定的循环迭代次数创建一个循环。
我猜,如果它应该是一个循环,那么幻灯片索引应该变成一个变量,但我不知道如何在 PowerPoint VBA 中做到这一点。
【问题讨论】:
标签: vba loops iteration powerpoint