vba - 使用母版在VBA中为PowerPoint 2010创建具有自定义布局的新幻灯片

标签 vba powerpoint powerpoint-2010

我具有以下VBA代码来创建新的PowerPoint幻灯片:

longSlideCount = ActivePresentation.Slides.Count

With ActivePresentation.Slides
    Set slideObject = .Add(longSlideCount + 1, ppLayoutTitle)
End With

...这会插入类型为“ppLayoutTitle”的新幻灯片,但是我想知道是否可以在“幻灯片主 View ”中创建自定义布局,然后将特定幻灯片模板的插入演示文稿中吗?

提前致谢!!!

最佳答案

您可以通过VBA通过CustomLayouts对象的 SlideMaster collection Presentation property访问所有自定义布局。创建自定义布局时,请为其赋予一个有意义的名称。然后,您可以从CustomLayouts集合中获取它。似乎Microsoft并未按名称实现查找,因此您将不得不遍历该集合以查找具有正确名称的CustomLayout对象。

一旦有了对所需CustomLayout对象的引用,就可以使用AddSlide集合的 Slides method,该集合将CustomLayout对象作为第二个参数(与您在问题中使用的Slides.Add相反,并使用PpSlideLayout枚举值) 。

以下是用于通过名称获取自定义布局的帮助方法,以及根据需要使用该示例的示例:

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 + 1, GetLayout("Smiley"))
End Sub

关于vba - 使用母版在VBA中为PowerPoint 2010创建具有自定义布局的新幻灯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20997571/

相关文章:

c# - 如何使用 Office Interop 在 PowerPoint 的自定义任务 Pane 中创建形状并将该形状添加到类别中

vba - 如何使 For 循环处理非整数

vba - 实时分享价格更新

Excel VBA 图表到 Powerpoint,每个图表都有单独的大小

vba - 添加空白幻灯片

vba - 如何使用 PowerPoint VBA 自动执行延迟屏幕捕获/粘贴过程?

vba - PowerPoint 文本转语音宏

excel - 使用 CopyFromRecordSet 时修剪空格

vba - 在 Excel 中处理 VBA Find 的结果

matlab - 如何在 Matlab 和 power point 或 Matlab 和 acrobat reader 之间进行通信