Hoan Cong
Hoan Cong

Reputation: 29

VBA character Font Style

Pretend I have a sentence like this: "THIS IS MY CASE:"

""

":" is regular and I want to change its style like The character before it(E). But I don't know which object to use in this case. I want to find The index of ":" then I check Font Style of character before it (index - 1) if they are different I will change Font Style of charater ":" (index) to index - 1.
I try TextFrame.TextRange.Font but there was something wrong.
Please help me, thank in advance.

Upvotes: 0

Views: 348

Answers (1)

Алексей Р
Алексей Р

Reputation: 7627

Try this code:

Sub test()
    Dim sh As Shape, EF As Font, textLen As Integer
    
    For Each sh In ActivePresentation.Slides(1).Shapes
        If sh.HasTextFrame Then
            textLen = sh.TextFrame.TextRange.Length
            
            If textLen > 1 Then
                Set EF = sh.TextFrame.TextRange.Characters(textLen - 1, 1).Font
                With sh.TextFrame.TextRange.Characters(textLen, 1).Font
                    .Name = EF.Name
                    .Color = EF.Color
                    .Size = EF.Size
                    .Italic = EF.Italic
                    .Bold = EF.Bold
                    .Underline = EF.Underline
                    ' and other required properties
                End With
            End If
        End If
    Next
End Sub

enter image description here

Upvotes: 3

Related Questions