假设slideShape是对形状对象的引用,要在PPT幻灯片中创建文本框,我可以使用以下代码:
slideShape.AddTextBox(Orientation, left, top, width, height)
slideShape.AddTextBox.Text = 'ABC-123 Feb 2015 Mike Smith'到目前一切尚好。但如果我想把这段文字分成三行:
ABC-123
Feb 2015
Mike Smith我需要对每一行进行颜色,调整大小,并应用不同的字体样式,我可以编写三个单独的slideShape.AddTextBox调用,但是这样做会创建3个不同的文本框。
是否可以在一个文本框中写3行?我不认为AddTextBox允许我那样做。我知道可以用其他的方法来做,但我不知道怎么做。
有什么建议吗?
发布于 2015-02-28 16:55:30
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发布于 2015-03-01 19:02:07
以oSh.TextFrame.TextRange .ParagraphFormat.SpaceAfter = 12结尾
.SpaceAfter以点为单位指定,文本大小也是如此。
https://stackoverflow.com/questions/28778195
复制相似问题