How to get the style name of this in VBA

Based on the screenshot I updated, in vba I could only get the stylename "MyStyle", how do I get the stylename "MyStyle + iltalic info as shown in my screenshot in vba???
Who is Participating?
GrahamSkanConnect With a Mentor RetiredCommented:
You would have to compare the font properties of the text with those of the Style and list the differences.

This snippet demonstrates for the size and the italic properties.

It requires a range object for input, e.g.

MsgBox Getstyle(Activedocument.Paragraphs(1).Range)
Function GetStyle(wdRange As Word.Range) As String
    Dim strStyleName As String
    Dim wdStyle As Style
    Set wdStyle = wdRange.Style
    If wdRange.Font.Size <> wdStyle.Font.Size Then
        strStyleName = wdRange.Style.NameLocal & " + " & wdRange.Font.Size & " pt"
    End If
    If wdRange.Font.Italic <> wdStyle.Font.Italic Then
        strStyleName = strStyleName & IIf(strStyleName = wdRange.Style.NameLocal, " + ", ", ") & _
                                      IIf(wdRange.Font.Italic, "", "Not ") & "Italic"
    End If
    GetStyle = strStyleName
End Function

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.