• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 792
  • Last Modified:

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???
Untitled.jpg
0
KenTan85
Asked:
KenTan85
1 Solution
 
GrahamSkanCommented:
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

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now