问题描述
我正在尝试使用 VBA 在 PowerPoint TextRange
中插入一些文本,我使用的是这样的:
I am trying to use VBA to insert some text into a PowerPoint TextRange
, I use something like this:
ActiveWindow.Selection.SlideRange.Shapes("rec1").TextFrame.TextRange.Text = "Hi"
但是,我不知道如何以编程方式应用粗体、斜体和下划线(我没有看到 .RichText 属性或类似的东西).
However, I can't figure out how to apply bold, italic and underline programmatically (I don't see a .RichText property or something similar).
我有一些简单的 HTML 文本,其中包含我想转换的粗体、斜体和带下划线的文本.
What I have is some simple HTML text with bold, italic and underlined text I would like to convert over.
如何做到这一点?
推荐答案
这可以通过使用 TextRange
的 Characters
、Words
轻松实现>、Sentences
、Runs
和 Paragraphs
对象,然后是 Font
对象设置粗体、下划线和斜体(其中其他属性).例如:
This is easily accomplished by using the TextRange
's Characters
, Words
, Sentences
, Runs
and Paragraphs
objects and then it's Font
object to set Bold, Underline and Italic (amongst other properties). For example:
Sub setTextDetails()
Dim tr As TextRange
Set tr = ActiveWindow.Selection.SlideRange.Shapes(1).TextFrame.TextRange
With tr
.Text = "Hi There Buddy!"
.Words(1).Font.Bold = msoTrue
.Runs(1).Font.Italic = msoTrue
.Paragraphs(1).Font.Underline = msoTrue
End With
End Sub
这篇关于以编程方式将字体格式应用于 PowerPoint 文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!