如何在 VBA for PowerPoint 2010 中定义标题文本和副标题文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20991697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to define title text and subtitle text in VBA for PowerPoint 2010
提问by HotDogCannon
I have the following code (VBA for PowerPoint 2010) to create a slide at the end of a presentation and insert title text:
我有以下代码(用于 PowerPoint 2010 的 VBA)在演示文稿结束时创建幻灯片并插入标题文本:
longSlideCount = ActivePresentation.Slides.Count
With ActivePresentation.Slides
Set slideObject = .Add(longSlideCount + 1, ppLayoutTitleOnly)
End With
slideObject.Shapes.Title.TextFrame.TextRange.Text = "This is the Main Title Text"
I would like to know how to:
我想知道如何:
- Insert 'Subtitle' text (smaller font, on a new line immediately below the main title text)
- Change the font and size of the main title text and the subtitle text
- 插入“副标题”文本(较小的字体,在主标题文本正下方的新行上)
- 更改主标题文本和副标题文本的字体和大小
Thanks in advance!!!
提前致谢!!!
采纳答案by Olle Sj?gren
You can do it in several ways depending on how you want the slide to look. The easiest may be to use the ppLayoutTitle
instead of ppLayoutTitleOnly
. It has two textframes instead of one, so you could update the text by using something like the following:
您可以通过多种方式执行此操作,具体取决于您希望幻灯片的外观。最简单的方法可能是使用ppLayoutTitle
代替ppLayoutTitleOnly
。它有两个文本框而不是一个,因此您可以使用以下内容更新文本:
slideObject.Shapes(2).TextFrame.TextRange.Text = "This is the subtitle."
If you need a more custom layout, you could add a new textbox by using adding the following at the bottom of your code example:
如果您需要更多自定义布局,可以通过在代码示例底部添加以下内容来添加新文本框:
Set oShp = slideObject.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 200, 300)
oShp.TextFrame.TextRange.Text = "Row #2: subtitle."
The numeric parameters to the AddTextbox
function set the position and size of the new textbox.
AddTextbox
函数的数字参数设置新文本框的位置和大小。
You can update the font the same way for both of the above examples (just change the reference to the textbox):
您可以为上述两个示例以相同的方式更新字体(只需更改对文本框的引用):
oShp.TextFrame.TextRange.Font.Bold = msoTrue