在 PowerPoint 中添加文本框
AddTextBox in PowerPoint
假设slideShape是对Shapes对象的引用,要在PPT幻灯片中创建一个文本框,我可以使用下面的代码:
slideShape.AddTextBox(Orientation, left, top, width, height)
slideShape.AddTextBox.Text = 'ABC-123 Feb 2015 Mike Smith'
到目前为止一切顺利。但是如果我想将文本分成 3 行:
ABC-123
Feb 2015
Mike Smith
并且我需要为每一行着色、调整大小并应用不同的字体样式,我可以编写三个单独的 slideShape.AddTextBox
调用,但这样做会创建 3 个单独的文本框。
是否可以在一个文本框中单独写3行?我认为 AddTextBox 不允许我这样做。我知道可以使用其他一些方法来完成,但我不确定该怎么做。
有什么建议吗?
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
与oSh.TextFrame.TextRange
.ParagraphFormat.SpaceAfter = 12
结束于
.SpaceAfter 以磅为单位指定,文本大小也是如此
假设slideShape是对Shapes对象的引用,要在PPT幻灯片中创建一个文本框,我可以使用下面的代码:
slideShape.AddTextBox(Orientation, left, top, width, height)
slideShape.AddTextBox.Text = 'ABC-123 Feb 2015 Mike Smith'
到目前为止一切顺利。但是如果我想将文本分成 3 行:
ABC-123
Feb 2015
Mike Smith
并且我需要为每一行着色、调整大小并应用不同的字体样式,我可以编写三个单独的 slideShape.AddTextBox
调用,但这样做会创建 3 个单独的文本框。
是否可以在一个文本框中单独写3行?我认为 AddTextBox 不允许我这样做。我知道可以使用其他一些方法来完成,但我不确定该怎么做。
有什么建议吗?
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
与oSh.TextFrame.TextRange .ParagraphFormat.SpaceAfter = 12 结束于
.SpaceAfter 以磅为单位指定,文本大小也是如此