none
How do I extract/export Style names and definitions from a Style Set or Template? RRS feed

  • Question

  • Micro: I want to see a list of the Style names and their characteristics from a Word template/Style Set. 

    Macro: Other people have defined Style Sets and Templates with a wide variety of formatting. Short of opening a document, applying the styles, and using Style Inspector for each style, is there a way to see what the Style definition includes, so I can decide whether to try and tweak the Style, or scrap it and start from scratch?

    I'm using Word 2010, on Windows 7.

    The Desktop Support Team has defined a Style Set called Company IT Style that is pushed out to every user on the network through the user's templates folder.

    C:\Users\%MyName%\AppData\Roaming\Microsoft\QuickStyles\Company IT QuickStyle Set.dotx

    I would like to export a list of the names of the styles included in this style set, along with the definitions/characteristics of each style, such as is revealed using the Modify Style button in the Styles list.

    For example: 
    **Normal:**  
    Font: (Default) Times New Roman, 11 pt, Left 
        Line spacing:  single, Space After:  6 pt, Widow/Orphan control, Style: Quick Style  
     
    **Heading1:**  
    Font: Arial Black, 16 pt, Indent: 
        Left:  0" 
        Hanging:  0.3", Space
        Before:  18 pt, After:  18 pt, Keep with next, Level 1 
        Tab stops:  0.3", List tab, Outline numbered + Level: 1 + Numbering Style: 1, 2, 3, … + Start at: 1 + Alignment: Left + Aligned at:  0" + Tab after:  0.3" + Indent at:  0.3", Style: Linked, Quick Style 
        Based on: Normal 
        Following style: Normal 

    There’s a macro at the Word Tips newsletter site that will reveal Template settings (PaperSize, Orientation, etc.) but I don’t know how to tweak that to reveal Style formatting characteristics.

    word.tips.net/T010117_Listing_the_Settings_in_a_Template.html

    I'm looking for a way to export the information from a given Style Set, ideally to a Word table that would show the Style name (formatted in that style), followed by a structured list of the elements of that style. Or even better, to XML.

    Is there a ready-made tool to do this?

    I'm a semi-power user of Word - probably the most advanced user in my department, but not an expert by any means. There are also others who are far better than I at coding in VBA.

    Any help or pointers appreciated.

    James

    • Moved by Max Meng Wednesday, December 5, 2012 6:42 AM (From:Word IT Pro Discussions)
    Tuesday, December 4, 2012 4:22 PM

Answers

  • Presented so others with the same question can use the answer.....

    As mentioned in the OP, I'm using Word 2010 on Windows 7.

    The "Print What" dropdown in the File->Print dialog offers the "Print Styles" option, but that only prints the definitions for the styles actively in use in that document.

    I was provided the following macro, which works in Word 2007 and 2010. As the author, Jessica Weissman, says,

    "Here's a macro I use in Word 2007 to list the descriptions of all paragraph and character styles in a document.  It skips table styles and list styles.  It lists all styles in the document, including those not in use.  

    If a style is based on another style, the description of the style includes only those things that differ from the base style.  Fortunately the base style is one of the items in a style description.

    If you want to see all styles of all types, comment out the If statement and the End If statement.

    Caveats:  it hasn't been stress tested and comes purely as is with no guarantees. 

    -  Jessica"

    Macro code follows - it's simpler than I thought.

    Sub describeAllStylesWeCareAbout()
    '  by Jessica Weissman
    Dim docActive As Document
    Dim docNew As Document
    Dim styleLoop As Style
    Set docActive = ActiveDocument
    Set docNew = Documents.Add
    For Each styleLoop In docActive.Styles
        
       If styleLoop.Type < 3 Then
      ' show only character and paragraph styles, not list or table styles
        With docNew.Range
            .InsertAfter Text:=styleLoop.NameLocal & Chr(9) _
                & styleLoop.Description
            .InsertParagraphAfter
            .InsertParagraphAfter
        End With
        End If
    Next styleLoop
    End Sub

    Wednesday, December 5, 2012 1:17 PM

All replies

  • Hi James

    <<Short of opening a document, applying the styles, and using Style Inspector for each style, is there a way to see what the Style definition includes, so I can decide whether to try and tweak the Style, or scrap it and start from scratch?>>

    You can open the *.dotx file directly, rather than creating a new document.

    Then you can have Word print a list of all style definitions in the document. You unfortunately don't mention which version of Word you're using and I'm not going to type out instructions for all the different permutations, but in essence Word has a "Print what" dropdown/list and you can choose Styles from that. See how far that gets you...


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, December 5, 2012 7:01 AM
    Moderator
  • Presented so others with the same question can use the answer.....

    As mentioned in the OP, I'm using Word 2010 on Windows 7.

    The "Print What" dropdown in the File->Print dialog offers the "Print Styles" option, but that only prints the definitions for the styles actively in use in that document.

    I was provided the following macro, which works in Word 2007 and 2010. As the author, Jessica Weissman, says,

    "Here's a macro I use in Word 2007 to list the descriptions of all paragraph and character styles in a document.  It skips table styles and list styles.  It lists all styles in the document, including those not in use.  

    If a style is based on another style, the description of the style includes only those things that differ from the base style.  Fortunately the base style is one of the items in a style description.

    If you want to see all styles of all types, comment out the If statement and the End If statement.

    Caveats:  it hasn't been stress tested and comes purely as is with no guarantees. 

    -  Jessica"

    Macro code follows - it's simpler than I thought.

    Sub describeAllStylesWeCareAbout()
    '  by Jessica Weissman
    Dim docActive As Document
    Dim docNew As Document
    Dim styleLoop As Style
    Set docActive = ActiveDocument
    Set docNew = Documents.Add
    For Each styleLoop In docActive.Styles
        
       If styleLoop.Type < 3 Then
      ' show only character and paragraph styles, not list or table styles
        With docNew.Range
            .InsertAfter Text:=styleLoop.NameLocal & Chr(9) _
                & styleLoop.Description
            .InsertParagraphAfter
            .InsertParagraphAfter
        End With
        End If
    Next styleLoop
    End Sub

    Wednesday, December 5, 2012 1:17 PM
    1. Change the extension of your document to .zip so MyTemplate.docx becomes MyTemplate.zip
    2. Open the zip file
    3. In the 'word' folder there is a file called styles.xml which contains all stules and it's settings. You can open it with Excel (as an XML table) to view it in a table format.
      (there is also a file called stylesWithEffects.xml it's mostly the same but there still is a difference, I didn't check what exactly is different).

    The challenge though is that many columns have names like val17, val18 etc so it's not always clear what the value means.

    Hope this helps
    JP



    • Edited by JeePeeNL Monday, October 3, 2016 7:51 AM
    Monday, October 3, 2016 7:49 AM