如何以编程方式更改幻灯片版式PowerPoint中? [英] How to change slide layout programmatically in PowerPoint?

查看:167
本文介绍了如何以编程方式更改幻灯片版式PowerPoint中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用C#programmaticaly更改幻灯片的布局(外接快讯2009年为Office和.NET使用)。如果新的布局是一个预定义之一,那么一切都很好,但如果我需要设置一个自定义布局为一个新的(不滑动再创造)。不幸的是,我没有找到如何做到这一点的任何信息,PowerPoint对象模型参考文档没有回答我的。还有就是创建一个使用自定义布局新幻灯片的能力。

I need to change a slide's layout programmaticaly with C# (Add-In Express 2009 for Office and .NET is used). If the new layout is a predefined one then everything is fine, but not if I need to set a custom layout as a new one (without slide recreating). Unfortunately, I didn't find any information on how to do it, PowerPoint object model reference documentation didn't answer me as well. There is just the ability to create a new slide that uses custom layout.

我已经做了一个实验,并已确保了幻灯片对象是住在同一,而我一直在改变布局预定义和自定义的。我不希望创建一个新的幻灯片时,我只需要切换布局。

I've done an experiment and have ensured that the Slide object stayed being the same while I have been changing layout both predefined and custom ones. I don't want to create a new slide when I need just switch the layout.

是否有可能呢?请帮我找到做这件事的方式。

Is it possible at all? Please help me to find a way of doing it.

推荐答案

将工作的唯一方法是,如果你的自定义布局实际使用在甲板上的第一。然后你只需采取的布局,并将其应用到你想要的幻灯片。您可以编程方式创建您的自定义布局新的幻灯片,用它的布局应用到另一张幻灯片,然后删除您已经创建了一个新的幻灯片。下面的代码将应用自定义布局(请注意,我的 ap.Slides(2) 是一个自定义布局)

The only way it will work is if your custom layout is actually used in the deck first. Then you simply take that layout and apply it to the slide you want. You could programatically create a new slide with your custom layout, use it's layout to apply to another slide and then delete that new slide you had created. Here's code to apply the custom layout (note that my ap.Slides(2) is a Custom Layout)

Sub ChangeLayout()
    Dim ap As Presentation
    Set ap = ActivePresentation
    Dim slide1 As Slide
    Set slide1 = ap.Slides(1)
    Dim customLayout As PpSlideLayout
    customLayout = ap.Slides(2).Layout
    slide1.Layout = ly
End Sub

这篇关于如何以编程方式更改幻灯片版式PowerPoint中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆