以编程方式将字体格式应用于PowerPoint文本 [英] Apply Font Formatting to PowerPoint Text Programmatically

查看:106
本文介绍了以编程方式将字体格式应用于PowerPoint文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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 字符单词句子运行 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文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆