在节的开头添加幻灯片
Adding a Slide at the beginning of a section
我正在尝试在 VBA 中为 PowerPoint 编写自动 agenda/table 内容生成器,它根据 PowerPoint 演示文稿中各节的标题生成议程要点。因为我还希望议程出现在每个部分的开头,所以我正在努力解决方法
.AddSlide(Index (I am inserting the ID of a section´s first slide here), pCustomLayout )
在该部分之前添加幻灯片(实际上是在上一节的末尾),因为它仅基于 ID 而不是说 "insert the slide at a section's beginning"。
是否有一个简单的解决方案(例如无需删除和重新创建该部分)来实现仅在一个部分的开头而不是在上一节的末尾创建幻灯片?
解决方案
Sub moveSlidesToSectionStart(pSectionIndex, pFirst, pLast)
Dim objPresentation As Presentation
Set objPresentation = Application.ActivePresentation
totalSlides = pLast - pFirst + 1
Dim arr()
ReDim arr(totalSlides - 1)
For i = 0 To totalSlides - 1 'fill array with all slides (slide numbers) that need to be moved
arr(i) = pFirst + i
Next i
objPresentation.Slides.Range(arr).MoveToSectionStart(pSectionIndex)
End Sub
您可以使用幻灯片上提供的 MoveToSectionStart 方法。传入节索引作为参数,它会将幻灯片放在该节的开头。
Function MoveSlideToSectionStart(Sld As Slide, SectionIndex As Long) As Boolean
If Sld.Parent.SectionProperties.Count < SectionIndex Then
MoveToSection = False
Exit Function
End If
Call Sld.MoveToSectionStart(SectionIndex)
MoveToSection = True
End Function
Sub Test()
Debug.Print MoveToSection(ActivePresentation.Slides(6), 1)
End Sub
我正在尝试在 VBA 中为 PowerPoint 编写自动 agenda/table 内容生成器,它根据 PowerPoint 演示文稿中各节的标题生成议程要点。因为我还希望议程出现在每个部分的开头,所以我正在努力解决方法
.AddSlide(Index (I am inserting the ID of a section´s first slide here), pCustomLayout )
在该部分之前添加幻灯片(实际上是在上一节的末尾),因为它仅基于 ID 而不是说 "insert the slide at a section's beginning"。
是否有一个简单的解决方案(例如无需删除和重新创建该部分)来实现仅在一个部分的开头而不是在上一节的末尾创建幻灯片?
解决方案
Sub moveSlidesToSectionStart(pSectionIndex, pFirst, pLast)
Dim objPresentation As Presentation
Set objPresentation = Application.ActivePresentation
totalSlides = pLast - pFirst + 1
Dim arr()
ReDim arr(totalSlides - 1)
For i = 0 To totalSlides - 1 'fill array with all slides (slide numbers) that need to be moved
arr(i) = pFirst + i
Next i
objPresentation.Slides.Range(arr).MoveToSectionStart(pSectionIndex)
End Sub
您可以使用幻灯片上提供的 MoveToSectionStart 方法。传入节索引作为参数,它会将幻灯片放在该节的开头。
Function MoveSlideToSectionStart(Sld As Slide, SectionIndex As Long) As Boolean
If Sld.Parent.SectionProperties.Count < SectionIndex Then
MoveToSection = False
Exit Function
End If
Call Sld.MoveToSectionStart(SectionIndex)
MoveToSection = True
End Function
Sub Test()
Debug.Print MoveToSection(ActivePresentation.Slides(6), 1)
End Sub