简体   繁体   English

Powerpoint VBA 选择一系列幻灯片

[英]Powerpoint VBA Select a Range of Slides

While there are many responses on how to set a range if you know the Indexes/Names, what I need is a way to select a range of slides without specifying each slide index or name.如果您知道索引/名称,有很多关于如何设置范围的回答,但我需要的是一种无需指定每个幻灯片索引或名称即可选择一系列幻灯片的方法。

I have a slide called "C2 Title" at the start of a section and a slide called "C2Approval" at the end of a section.我在一节的开头有一张名为“C2 Title”的幻灯片,在一节的末尾有一张名为“C2Approval”的幻灯片。 The amount of slides between the two will vary depending on if users add slides in the middle.两者之间的幻灯片数量将根据用户是否在中间添加幻灯片而有所不同。 I want to select all the slides in between the two regardless of how many slides are inserted.无论插入了多少张幻灯片,我都想选择两者之间的所有幻灯片。

I suspect there is a way to loop through the indexes to populate the array but I cannot seem to figure out how to do that.我怀疑有一种方法可以遍历索引以填充数组,但我似乎无法弄清楚如何做到这一点。

UPDATE: Per request below here is what I've tried更新:下面的每个请求是我尝试过的

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

Thanks Steve Rindsberg that was a great idea and got it to work感谢 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM