Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-18-2014, 06:51 AM
ljd108 ljd108 is offline Macro to list all character styles in a document Windows Vista Macro to list all character styles in a document Office 2010 32bit
Novice
Macro to list all character styles in a document
 
Join Date: Oct 2014
Posts: 24
ljd108 is on a distinguished road
Default Macro to list all character styles in a document

Hi,



I currently have a macro that is able to produce a list of all paragraph styles in a word document (see below). I was wondering if it is possible to adapt this code/create a new code to produce a list of charater styles instead of paragraph styles?

Thanks

Code:

Code:
Sub CreateStyleList()
    Dim docThis As Document
    Dim styItem As Style
    Dim sBuiltIn(499) As String
    Dim iStyBICount As Integer
    Dim sUserDef(499) As String
    Dim iStyUDCount As Integer
    Dim sInUse(499) As String
    Dim iStyIUCount As Integer
    Dim iParCount As Integer
    Dim J As Integer, K As Integer
    Dim sParStyle As String
    Dim bInUse As Boolean
    
    ' Ref the active document
    Set docThis = ActiveDocument
    
    ' Collect all styles being used
    iStyIUCount = 0
    iParCount = docThis.Paragraphs.Count
    iParOut = 0
    For J = 1 To iParCount
        sParStyle = docThis.Paragraphs(J).Style
        For K = 1 To iStyIUCount
            If sParStyle = sInUse(K) Then Exit For
        Next K
        If K = iStyIUCount + 1 Then
            iStyIUCount = K
            sInUse(iStyIUCount) = sParStyle
        End If
    Next J
    
    iStyBICount = 0
    iStyUDCount = 0
    ' Check out styles that are "in use"
    For Each styItem In docThis.Styles
        'see if in those being used
        bInUse = False
        For J = 1 To iStyIUCount
            If styItem.NameLocal = sInUse(J) Then bInUse = True
        Next J
        'Add to those not in use
        If Not bInUse Then
            If styItem.BuiltIn Then
                iStyBICount = iStyBICount + 1
                sBuiltIn(iStyBICount) = styItem.NameLocal
            Else
                iStyUDCount = iStyUDCount + 1
                sUserDef(iStyUDCount) = styItem.NameLocal
            End If
        End If
    Next styItem
    
    'Now create the output document
    Documents.Add
    
    Selection.TypeText "Styles In Use"
    Selection.TypeParagraph
    For J = 1 To iStyIUCount
        Selection.TypeText sInUse(J)
        Selection.TypeParagraph
    Next J
    Selection.TypeParagraph
    Selection.TypeParagraph
    
    Selection.TypeText "Built-in Styles Not In Use"
    Selection.TypeParagraph
    For J = 1 To iStyIUCount
        Selection.TypeText sBuiltIn(J)
        Selection.TypeParagraph
    Next J
    Selection.TypeParagraph
    Selection.TypeParagraph
    
    Selection.TypeText "User-defined Styles Not In Use"
    Selection.TypeParagraph
    For J = 1 To iStyIUCount
        Selection.TypeText sUserDef(J)
        Selection.TypeParagraph
    Next J
    Selection.TypeParagraph
    Selection.TypeParagraph
End Sub
Reply With Quote
 



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 11:49 AM.


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