vba - 将幻灯片添加到部分
问题描述
我正在尝试将使用以下代码创建的幻灯片添加到名为“索引”的特定部分。
目前它在最后一张下方的两张幻灯片,但由于幻灯片的数量将链接我无法使用 -2 函数引用,所以我不得不求助于部分引用。
Public Function GetLayout( _
LayoutName As String, _
Optional ParentPresentation As Presentation = Nothing) As CustomLayout
If ParentPresentation Is Nothing Then
Set ParentPresentation = ActivePresentation
End If
Dim oLayout As CustomLayout
For Each oLayout In ParentPresentation.SlideMaster.CustomLayouts
If oLayout.Name = LayoutName Then
Set GetLayout = oLayout
Exit For
End If
Next
End Function
Sub AddCustomSlide()
Dim oSlides As Slides, oSlide As Slide
Set oSlides = ActivePresentation.Slides
Set oSlide = oSlides.AddSlide(oSlides.Count - 2, GetLayout("Processwindow"))
End Sub
解决方案
解决方法是使用对象的.MoveToSectionStart
方法Slide
。
在您的AddCustomSlide
例程中,添加一行:
Sub AddCustomSlide()
Dim oSlides As Slides, oSlide As Slide
Set oSlides = ActivePresentation.Slides
Set oSlide = oSlides.AddSlide(oSlides.Count - 2, GetLayout("Title Only"))
oSlide.MoveToSectionStart GetSectionNumber("Index")
End Sub
由于您需要“索引”部分的部分编号,因此我编写了一个快速函数来返回该编号:
Private Function GetSectionNumber( _
ByVal sectionName As String, _
Optional ParentPresentation As Presentation = Nothing) As Long
If ParentPresentation Is Nothing Then
Set ParentPresentation = ActivePresentation
End If
GetSectionNumber = -1
With ParentPresentation.SectionProperties
Dim i As Long
For i = 1 To .Count
If .Name(i) = sectionName Then
GetSectionNumber = i
Exit Function
End If
Next i
End With
End Function
推荐阅读
- c# - Microsoft 认知服务语音识别结果到 C# 中的字符串
- r - 使用 data.table 过滤和分组
- android - Firebase 云消息传递的定时通知
- java - 如何将字符串转换为 JSONObject?
- javascript - 显示时如何隐藏元素:无不起作用
- javascript - React native - 有没有办法使用来自另一个页面的对象?
- javascript - 渲染 DOM 时冻结 CSS 动画
- oracle - 使用文本导入器导入时数据库中的符号不正确
- reactjs - 如何使 iframe 内的反应视频播放器响应
- redux - SyntaxError:请求的模块“redux”不提供名为“createStore”的导出