首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AddTextBox in PowerPoint

AddTextBox in PowerPoint
EN

Stack Overflow用户
提问于 2015-02-28 04:48:43
回答 2查看 1.7K关注 0票数 0

假设slideShape是对形状对象的引用,要在PPT幻灯片中创建文本框,我可以使用以下代码:

代码语言:javascript
复制
slideShape.AddTextBox(Orientation, left, top, width, height)
slideShape.AddTextBox.Text = 'ABC-123 Feb 2015 Mike Smith'

到目前一切尚好。但如果我想把这段文字分成三行:

代码语言:javascript
复制
ABC-123 
Feb 2015 
Mike Smith

我需要对每一行进行颜色,调整大小,并应用不同的字体样式,我可以编写三个单独的slideShape.AddTextBox调用,但是这样做会创建3个不同的文本框。

是否可以在一个文本框中写3行?我不认为AddTextBox允许我那样做。我知道可以用其他的方法来做,但我不知道怎么做。

有什么建议吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-28 16:55:30

代码语言:javascript
复制
Sub Thing()

    ' Some setup to add a text box
    Dim oSl As Slide
    Dim oSh As Shape

    Set oSl = ActivePresentation.Slides(1)
    Set oSh = oSl.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, 500, 500)

    ' But add the tex like so ... with a CR/LF pair at the end of every line:
    oSh.TextFrame.TextRange.Text = "ABC-123" & vbCrLf & "Feb 2015" & vbCrLf & "Mike Smith"

    ' The shape's TextRange has a .Paragraphs collection that you can address
    ' a paragraph at a time.
    ' Note: there's also a .Lines collection
    With oSh.TextFrame.TextRange
        .Paragraphs(1).Font.Color.RGB = RGB(255, 0, 0)
        .Paragraphs(2).Font.Color.RGB = RGB(0, 255, 0)
        .Paragraphs(3).Font.Color.RGB = RGB(0, 0, 255)
    End With

End Sub
票数 0
EN

Stack Overflow用户

发布于 2015-03-01 19:02:07

以oSh.TextFrame.TextRange .ParagraphFormat.SpaceAfter = 12结尾

.SpaceAfter以点为单位指定,文本大小也是如此。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28778195

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档