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

编程入门 行业动态 更新时间:2024-10-08 06:25:01
本文介绍了使用母版在VBA中为PowerPoint 2010创建具有自定义布局的新幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

longSlideCount = ActivePresentation.Slides.Count 具有ActivePresentation.Slides 设置slideObject = .Add(longSlideCount + 1,ppLayoutTitle)以结尾

...这会插入类型为 ppLayoutTitle的新幻灯片,但我想知道是否可以在幻灯片主视图中创建自定义布局,然后插入

预先感谢!

解决方案方案

所有自定义布局都可以通过 CustomLayouts 集合 library / office / ff745484(v = office.14).aspx rel = noreferrer> 演示文稿 SlideMaster 属性 / code> obj等等。创建自定义布局时,请为其赋予一个有意义的名称。然后,您可以从 CustomLayouts 集合中获取它。似乎Microsoft并未按名称实现查找,因此您将不得不遍历该集合以查找具有正确名称的 CustomLayout 对象。

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

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

公共函数GetLayout(_ LayoutName作为字符串,_ 可选ParentPresentation作为表示= Nothing)作为CustomLayout 如果ParentPresentation没有然后设置ParentPresentation = ActivePresentation 如果 Dim oLayout作为CustomLayout 对于ParentPresentation.SlideMaster.CustomLayouts中的每个oLayout 如果oLayout.Name = LayoutName然后设置GetLayout = oLayout 退出结束如果下一个结束函数 Sub AddCustomSlide() Dim oSlides作为幻灯片,作为oSlide作为幻灯片设置oSlides = ActivePresentation.Slides 设置oSlide = oSlides.AddSlide(oSlides.Count + 1,GetLayout( Smiley))结束子

I have the following VBA code to create a new PowerPoint slide:

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

...which inserts a new slide of type 'ppLayoutTitle', but I am wondering if it is possible to create a custom layout in the 'Slide Master View' and then insert that particular slide template into the presentation?

Thanks in advance!!!

解决方案

All your custom layouts can be accessed via VBA through the CustomLayoutscollection of the SlideMaster property of a Presentation object. When you create a custom layout, give it a meaningful name. Then you can fetch it from the CustomLayouts collection. It appears that Microsoft didn't implement lookup by name, so you will have to iterate through the collection to find the CustomLayout object with the right name.

Once you have a reference to the desired CustomLayout object, you use the AddSlide method of the Slides collection, which takes a CustomLayout object as the second arguments (as opposed to Slides.Add, which you used in your question, and which takes a PpSlideLayout enumeration value).

Below is a helper method for fetching a custom layout by name, and example of using it as you wanted:

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中为PowerPoint 2010创建具有自定义布局的新幻灯片

本文发布于:2023-10-31 10:26:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545809.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   幻灯片   中为   布局   母版

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!