vbapowerpointpowerpoint-2013

How do I format individual lines in a textbox via Microsoft PowerPoint macros?


I want a textbox where the first line and subsequent lines of text have different formatting, but they must be in the same textbox. This is what I currently have, which applies the same formatting to all text.

Sub geberateSlide() 
  ...
  With currSlide.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
  Left:=0, Top:=0, Width:=headerWidth, Height:=headerHeight)
    .TextFrame.TextRange.Text = "Test Box" & vbCrLf & "Description"
    .TextFrame.AutoSize = ppAutoSizeNone
    .Height = headerHeight
    .Line.ForeColor.RGB = RGB(0,0,0)
    .Line.Visible = True
  End With
...
End Sub

The text should be Arial 8. Line 1 should be black and bold, while subsequent text should be blue.


Solution

  • .TextFrame.TextRange.Lines(0, 1) will target the first line.

    enter image description here

    %300 Zoom

    With currSlide.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
                                     Left:=0, Top:=0, Width:=headerWidth, Height:=headerHeight)
        .Height = headerHeight
        .TextFrame.AutoSize = ppAutoSizeNone
        With .TextFrame.TextRange
            .Text = "Test Box" & vbCrLf & "Description"
            With .Font
                .Color = vbBlue
                .Size = 8
                .Name = "Arial"
            End With
    
            With .Lines(1).Font
                .Color = vbBlack
                .Bold = msoTrue
            End With
        End With
    End With