PowerPoint VBA formatting a shape TextBox.

In PowerPoint to format a shape textbox requires to access methods like “Paragraphs”, “Words”, “Lines”, “Sentences”, “Characters”. By the way the first element is one (1) not zero (0).

To change Font Color to Yellow for the first word
.Words(1).Font.Color = vbYellow

To change Font Color to Red for the first 10 letters
.Characters(1, 10).Font.Color = vbRed

To change Font Color to Blue for the second line
.Lines(2).Font.Color = vbBlue

Keep in mind: a paragraph is delimited by a carriage return or the use of vbNewLine so if you have a text like this:
"A" + vbNewLine + vbNewLine + "B"
Then you have 3 paragraphs, the one between the vbNewLine IS a paragraph too.


The above TextBox was created with the following code:

Public Sub Custom()
    Dim p1 As String, p2 As String
    p1 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod " & _
         "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, " & _
         "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." & _
         "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat" & _
         "nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia" & _
         "deserunt mollit anim id est laborum
    p2 = "_________________________" & vbNewLine & "Signature"
    Dim sld As Slide
    Dim shp As Shape
    Set sld = Application.ActiveWindow.View.Slide
    Set shp = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, 30, 30, 650, 140)
    With shp.TextFrame.TextRange
        .Font.Name = "Arial"
        .Font.Size = 12
        .ParagraphFormat.Alignment = ppAlignJustify
        'Set the text
        .Text = p1 & vbNewLine & vbNewLine & _
                p1 & vbNewLine & vbNewLine & _
                p1 & vbNewLine & vbNewLine & _
                vbNewLine & p2
        'Space between lines set to 1.5
        .Lines.ParagraphFormat.SpaceWithin = 1.5
        .Paragraphs(1).Font.Bold = msoTrue
        .Paragraphs(1).Font.Color = vbBlue
        .Paragraphs(3).Font.Bold = msoFalse
        .Paragraphs(3).Font.Color = vbGreen
        .Paragraphs(5).Font.Bold = msoTrue
        .Paragraphs(5).Font.Color = vbRed
        'Signature Line
        .Paragraphs(8).Font.Size = 16
        .Paragraphs(8).Font.Bold = msoTrue
        .Paragraphs(8).ParagraphFormat.Alignment = ppAlignCenter
        .Paragraphs(9).Font.Size = 16
        .Paragraphs(9).Font.Bold = msoTrue
        .Paragraphs(9).Font.Italic = msoTrue
        .Paragraphs(9).ParagraphFormat.Alignment = ppAlignCenter
    End With
End Sub
This entry was posted in PowerPoint and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s