Apply font formatting to PowerPoint text programmatically

I am trying to use VBA to insert text in PowerPoint TextRange, I am using something like this:

ActiveWindow.Selection.SlideRange.Shapes("rec1").TextFrame.TextRange.Text = "Hi"

However, I cannot figure out how to apply bold, italics, and underlining programmatically (I don't see the .RichText property or anything like that).

I have plain HTML text with bold, italics and underlined text that I would like to convert.

How to do it?

+5
source share
3 answers

TextRange Characters, Words, Sentences, Runs Paragraphs, Font Bold, Underline Italic ( ). :

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
+8

MSDN TextRange. , Font TextRange.

: , Bold Italics, :

TextRange.Font.Bold = msoTrue

EDIT EDIT: , . . :

, , . :

Application.ActiveDocument.Pages(1).Shapes(2) _
.TextFrame.TextRange.Words(Start:=2, Length:=3) _
.Font.Bold = True

" ".

+4

In addition to the answer above, you should try to name the objects that you will change, since selecting them in the middle of the presentation may cause PowerPoint to act weirdly. Create a new TextRange object and set it like this.

dim mytextrange As TextRange
Set mytextrange = ActiveDocument.Pages(1).Shapes(2).TextFrame.TextRange
mytextrange.Words...
+3
source

All Articles