簡體   English   中英

使用Master通過自定義布局在VBA for PowerPoint 2010中創建新幻燈片

[英]Create a new slide in VBA for PowerPoint 2010 with custom layout using Master

我有以下VBA代碼來創建一個新的PowerPoint幻燈片:

longSlideCount = ActivePresentation.Slides.Count

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

...插入'ppLayoutTitle'類型的新幻燈片,但我想知道是否可以在'幻燈片母版視圖'中創建自定義布局,然后將該特定幻燈片模板插入到演示文稿中?

提前致謝!!!

您所有的自定義布局可以通過VBA通過訪問CustomLayouts收集的的SlideMaster財產一的Presentation對象。 創建自定義布局時,請為其指定有意義的名稱。 然后,您可以從CustomLayouts集合中獲取它。 看起來Microsoft沒有按名稱實現查找,因此您必須遍歷該集合才能找到具有正確名稱的CustomLayout對象。

一旦你有所需的參考CustomLayout對象,您使用AddSlide方法中的Slides集合,它需要一個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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM