Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 11-18-2014, 03:57 PM
macropod's Avatar
macropod macropod is online now Macro to list all character styles in a document Windows 7 64bit Macro to list all character styles in a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The following macro will produce a report of all Styles in the document, in a sorted table format.
Code:
Sub ReportAllStyles()
Dim Sty As Style, StrAttr As String, Rng As Range
StrAttr = "Style Name" & vbTab & "Type" & vbTab & "Built In" & vbTab & "In Use"
With ActiveDocument
  For Each Sty In .Styles
    With Sty
      StrAttr = StrAttr & vbCr & .NameLocal & vbTab
      Select Case .Type
        Case wdStyleTypeCharacter:     StrAttr = StrAttr & "Character" & vbTab
        Case wdStyleTypeLinked:        StrAttr = StrAttr & "Linked" & vbTab
        Case wdStyleTypeList:          StrAttr = StrAttr & "List" & vbTab
        Case wdStyleTypeParagraph:     StrAttr = StrAttr & "Paragraph" & vbTab
        Case wdStyleTypeParagraphOnly: StrAttr = StrAttr & "ParagraphOnly" & vbTab
        Case wdStyleTypeTable:         StrAttr = StrAttr & "Table" & vbTab
      End Select
      Select Case .BuiltIn
        Case True:                     StrAttr = StrAttr & "Y" & vbTab
        Case Else:                     StrAttr = StrAttr & "N" & vbTab
      End Select
      Select Case .InUse
        Case True:                     StrAttr = StrAttr & "Y"
        Case Else:                     StrAttr = StrAttr & "N"
      End Select
    End With
  Next
  Set Rng = .Characters.Last
  With Rng
    .InsertAfter vbCr
    .Collapse wdCollapseEnd
    .Text = StrAttr
    .ConvertToTable Separator:=vbTab, NumColumns:=4, AutoFit:=True, _
      AutoFitBehavior:=wdAutoFitContent, DefaultTableBehavior:=wdWord9TableBehavior
    With .Tables(1)
      With .Rows(1)
        .HeadingFormat = True
        .Range.Font.Bold = True
      End With
      .Borders.Enable = False
      .Rows.Alignment = wdAlignRowCenter
      .Sort ExcludeHeader:=True, CaseSensitive:=False, LanguageID:=wdLanguageNone, _
        FieldNumber:="Column 2", SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, _
        FieldNumber2:="Column 3", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:=wdSortOrderAscending, _
        FieldNumber3:="Column 4", SortFieldType3:=wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending
    End With
  End With
End With
End Sub
To reduce the report to just Character Styles, you could use:
Code:
Sub ReportCharacterStyles()
Dim Sty As Style, StrAttr As String, Rng As Range
StrAttr = "Style Name" & vbTab & "Type" & vbTab & "Built In" & vbTab & "In Use"
With ActiveDocument
  For Each Sty In .Styles
    With Sty
      Select Case .Type
        Case wdStyleTypeCharacter
          StrAttr = StrAttr & vbCr & .NameLocal & vbTab
          StrAttr = StrAttr & "Character" & vbTab
          Select Case .BuiltIn
            Case True:                     StrAttr = StrAttr & "Y" & vbTab
            Case Else:                     StrAttr = StrAttr & "N" & vbTab
          End Select
          Select Case .InUse
            Case True:                     StrAttr = StrAttr & "Y"
            Case Else:                     StrAttr = StrAttr & "N"
          End Select
      End Select
    End With
  Next
  Set Rng = .Characters.Last
  With Rng
    .InsertAfter vbCr
    .Collapse wdCollapseEnd
    .Text = StrAttr
    .ConvertToTable Separator:=vbTab, NumColumns:=4, AutoFit:=True, _
      AutoFitBehavior:=wdAutoFitContent, DefaultTableBehavior:=wdWord9TableBehavior
    With .Tables(1)
      With .Rows(1)
        .HeadingFormat = True
        .Range.Font.Bold = True
      End With
      .Borders.Enable = False
      .Rows.Alignment = wdAlignRowCenter
      .Sort ExcludeHeader:=True, CaseSensitive:=False, LanguageID:=wdLanguageNone, _
        FieldNumber:="Column 2", SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, _
        FieldNumber2:="Column 3", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:=wdSortOrderAscending, _
        FieldNumber3:="Column 4", SortFieldType3:=wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending
    End With
  End With
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to list all character styles in a document Font list character display whabtewo Word 1 03-09-2014 08:12 PM
Macro to list all character styles in a document MAcro to List all the Font & its size in a word document shaukat74 Word VBA 1 01-29-2013 09:34 PM
Macro to list all character styles in a document Restricting paragraph styles without restricting character styles Red Pill Word 5 05-25-2012 01:06 PM
Macro to list all character styles in a document Quick Styles Set saved but it doesnt appear at the styles list! Pedro77 Word 3 10-15-2011 05:17 AM
Macro to list all character styles in a document The list of styles appears in different way in different document????? Jamal NUMAN Word 4 04-28-2011 05:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft