How to get the style name of this in VBA

Posted on 2009-02-17
Last Modified: 2013-11-10
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???
Question by:KenTan85
    1 Comment
    LVL 76

    Accepted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
    This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
    This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now