【问题标题】:Powerpoint VBA Select a Range of SlidesPowerpoint VBA 选择一系列幻灯片
【发布时间】:2020-07-03 06:49:12
【问题描述】:

如果您知道索引/名称,有很多关于如何设置范围的回答,但我需要的是一种无需指定每个幻灯片索引或名称即可选择幻灯片范围的方法。

我在一节的开头有一张名为“C2 Title”的幻灯片,在一节的结尾有一张名为“C2Approval”的幻灯片。两者之间的幻灯片数量将根据用户是否在中间添加幻灯片而有所不同。无论插入多少张幻灯片,我都想选择两者之间的所有幻灯片。

我怀疑有一种方法可以遍历索引以填充数组,但我似乎无法弄清楚如何做到这一点。

更新:下面的每个请求都是我尝试过的

Sub SelectSection()
Dim sIndex As Long
Dim eIndex As Long
Dim sArray() As Long
Dim sSlides As SlideRange


ActivePresentation.Slides("C2Title").Select
sIndex = ActiveWindow.Selection.SlideRange.SlideIndex

ActivePresentation.Slides("C2DirectionalApproval").Select
eIndex = ActiveWindow.Selection.SlideRange.SlideIndex

'This solution only gets the first/last slide of range
Set sSlides = ActivePresentation.Slides.Range(Array(eIndex - 1, sIndex + 1))

'Problem is this assumes I've already selected Slides
sSlides = ActiveWindow.Selection.SlideRange
 ReDim myArray(1 To sSlides.count)
      For y = LBound(sArray) To UBound(myArray)
        sArray(y) = Slides(y).SlideIndex
      Next y



End Sub

【问题讨论】:

  • 嗨。请分享您迄今为止所尝试的更多细节!
  • 您可以只枚举该部分中的幻灯片并填充它。以下是部分代码 - skphub.com/2010/ppt001.htm
  • 这是做什么的? sSlides.count 只是 eindex-sindex-1。您是否尝试将幻灯片范围的索引加载到数组中?
  • 我在几个网站上找到了 sslides 代码,作为定义数组中所有幻灯片的一种方式,但我不知道它应该如何工作。我的目标是选择 C2Title 和 C2Approval 幻灯片之间的所有幻灯片
  • @H_Thurber 您真的需要选择所有幻灯片吗?如果你能找到第一张和最后一张幻灯片的索引,那么你可能只需要一个 For x = FirstSlideIndex to LastSlideIndex [do stuff with Slide(x)] Next loop

标签: vba powerpoint


【解决方案1】:

感谢 Steve Rindsberg,这是一个很棒的想法并让它发挥作用

Sub SelectSection()
Dim eIndex As Long 'Index of End of Selection of Slide
Dim lIndex As Long 'Index used to select slides in loop
Dim pIndex As Long 'Index used to determine paste spot

lIndex = ActivePresentation.Slides("C2Title").SlideIndex + 1
eIndex = ActivePresentation.Slides("C2Approval").SlideIndex
pIndex = ActivePresentation.Slides("C3Title").SlideIndex


ActivePresentation.Slides(lIndex).Select
Do While (ActiveWindow.Selection.SlideRange.SlideIndex < eIndex)
'Copies the selected slide
ActivePresentation.Slides(lIndex).Copy
'Selects next slide in Chapter 3, pastes in copied slide and changes subtitle
ActivePresentation.Slides(pIndex).Select
pIndex = pIndex + 1
ActivePresentation.Slides.Paste Index:=pIndex
ActivePresentation.Slides(pIndex).Shapes("Subtitle").TextFrame.TextRange.Text = "Chapter 3: Information Systems Architecture"
'Selects next slide in presentation
ActivePresentation.Slides(lIndex).Select
lIndex = lIndex + 1
'Selects slide to copy
ActivePresentation.Slides(lIndex).Select
Loop

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多