您的所有自定义布局都可以通过 VBA 通过对象属性的CustomLayouts
集合进行访问。创建自定义布局时,请为其指定一个有意义的名称。然后你可以从集合中获取它。Microsoft 似乎没有实现按名称查找,因此您必须遍历集合才能找到具有正确名称的对象。SlideMaster
Presentation
CustomLayouts
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