How to apply a specific layout in powerpoint using vba?

I am working on one project. In this, I created one special theme that includes one master slide and can have layouts. so basically I want to apply a specific layout to specific slides. So is there any way to do this programmatically. eg:

activepresentation.Slides (1) .Layout = "layoutname"

I know the code above, but I want something like this to call a specific layout by its name. for your information, my layout name is "Name without customer logo."

thank

+5
source share
2 answers

ActivePresentation.Slides (1) .CustomLayout = ActivePresentation.Designs (1) .SlideMaster.CustomLayouts (x)

x - , .

PPT OM, , , , . .

, , CustomLayouts , , , .

+4

Sub ApplyLayoutByIndex()

    Dim sld As Slide
    Dim shp As Shape
    Dim xName As String
    Set sld = Application.ActiveWindow.View.Slide
    Dim xIndex As Integer

    xName = "A final slide"

    xIndex = getLayoutIndexByName(xName)

    If xIndex = 0 Then
    MsgBox "The layout name" & xName & "not found. Check the name of the layout", vbOKOnly
    Exit Sub
    End If

    sld.CustomLayout = ActivePresentation.Designs(1).SlideMaster.CustomLayouts(xIndex)

    End Sub

    Function getLayoutIndexByName(xName As String) As Integer
    ActivePresentation.Designs(1).SlideMaster.CustomLayouts.Item (1)
    With ActivePresentation.Designs(1).SlideMaster.CustomLayouts
        For i = 1 To .Count
            If .Item(i).Name = xName Then
            getLayoutIndexByName = i
            Exit Function
            End If
        Next
    End With

    End Function

!

+3

All Articles