复制 CustomLayout 并将其插入到常规幻灯片中

Copy CustomLayout and Insert It Into a Regular Slide

我想在常规演示文稿中创建所有 CustomLayouts 的概览幻灯片。

以下代码会引发错误 -- 该方法也无法手动工作:

Sub CreateOverviewSlideFromLayouts()
    Dim myCustomLayout As CustomLayout
    Dim myBlankSlide As slide
    Set myBlankSlide = ActivePresentation.Slides.Add(Index:=2, Layout:=ppLayoutBlank)
    For Each myCustomLayout In ActivePresentation.Designs(1).slideMaster.CustomLayouts
        myCustomLayout.Copy
        myBlankSlide.Shapes.PasteSpecial ppPasteJPG '<== this raises an error
    Next myCustomLayout
End Sub

如何复制 CustomLayout 并将该副本插入到普通幻灯片中?

这可能有帮助:

Sub ThemeSampler()

    Dim oSl As Slide
    Dim oSh As Shape
    Dim oLayout As CustomLayout
    Dim oDesign As Design
    Dim sPictureName As String
    
    ' Point to a picture that'll be used on some slide.
    ' change this to suit your needs:
    sPictureName = "C:\Users\Public\Pictures\Sample Pictures\Forest.jpg"
    
    With ActivePresentation
        For Each oDesign In .Designs
            For Each oLayout In oDesign.SlideMaster.CustomLayouts
                Set oSl = .Slides.AddSlide(.Slides.Count, oLayout)
                ' ID the slide:
                Set oSh = oSl.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 10, 300, 50)
                With oSh.TextFrame.TextRange
                    .Text = oLayout.Name
                End With
                ' now fill the slide's placeholders with stuff
                For Each oSh In oSl.Shapes
                    If oSh.Type = msoPlaceholder Then
                        Select Case oSh.PlaceholderFormat.Type
                            Case ppPlaceholderBody, ppPlaceholderVerticalBody
                                oSh.TextFrame.TextRange.Text = _
                                    "Bulleted text" & vbCrLf _
                                    & "Bulleted text" & vbCrLf
                            Case ppPlaceholderObject
                                oSh.TextFrame.TextRange.Text = _
                                    "Bulleted text" & vbCrLf _
                                    & "Bulleted text" & vbCrLf
                            
                            Case ppPlaceholderTitle, ppPlaceholderCenterTitle, ppPlaceholderVerticalTitle
                                oSh.TextFrame.TextRange.Text = "Slide Title"
                            
                            Case ppPlaceholderChart
                            
                            Case ppPlaceholderDate
                                oSh.TextFrame.TextRange.Text = "12/34/56"
                            
                            Case ppPlaceholderFooter
                                oSh.TextFrame.TextRange.Text = "Footer goes here"
                            
                            Case ppPlaceholderHeader
                                oSh.TextFrame.TextRange.Text = "Header goes here"
                            
                            Case ppPlaceholderMediaClip
                            
                            Case ppPlaceholderPicture
                                oSh.Fill.UserPicture (sPictureName)
                                
                            Case ppPlaceholderSubtitle
                                oSh.TextFrame.TextRange.Text = "Subtitle goes here"
                            Case ppPlaceholderTable
                                If oSh.HasTable Then
                                    oSh.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = "Cell 1,1"
                                    oSh.Table.Cell(5, 5).Shape.TextFrame.TextRange.Text = "Cell 5,5"
                                End If
                            
                        End Select
                    End If
                Next
            Next    ' Layout
        Next    ' Design
    End With
    

End Sub