Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 11-18-2014, 07:58 PM
macropod's Avatar
macropod macropod is offline 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 .InUse property tends to do that, presumably because of some design quirk with how MS has defined them. The only way around the behaviour is to use Find to search for document content actually using a given Style. Checking the body of the document is trivial, checking headers, footers, textboxes, footnotes, endnotes, etc. requires a lot more processing. To that end, you could change:
Code:
          Select Case .InUse
            Case True:                     StrAttr = StrAttr & "Y"
            Case Else:                     StrAttr = StrAttr & "N"
          End Select
to:
Code:
      Select Case .InUse
        Case False:                     StrAttr = StrAttr & "N"
        Case Else:                      StrAttr = StrAttr & StyleInUse(ActiveDocument, Sty)
      End Select
and, after the existing sub, add:
Code:
Function StyleInUse(Doc As Document, Sty As Style) As String
Dim Sctn As Section, HdFt As HeaderFooter, Shp As Shape, FtNt As Footnote, E_Nt As Endnote, StrRslt As String, bRslt As Boolean
StrRslt = "N"
With Doc
  bRslt = FindStyle(.Range, Sty)
  If bRslt = True Then GoTo Result
  For Each Sctn In .Sections
    For Each HdFt In Sctn.Headers
      If FindStyle(HdFt.Range, Sty) = True Then GoTo Result
      For Each Shp In HdFt.Range.ShapeRange
        With Shp
          If Not .TextFrame Is Nothing Then
            bRslt = FindStyle(.TextFrame.TextRange, Sty)
            If bRslt = True Then GoTo Result
          End If
        End With
      Next
    Next
    For Each HdFt In Sctn.Footers
      bRslt = FindStyle(HdFt.Range, Sty)
      If bRslt = True Then GoTo Result
      For Each Shp In HdFt.Range.ShapeRange
        With Shp
          If Not .TextFrame Is Nothing Then
            bRslt = FindStyle(.TextFrame.TextRange, Sty)
            If bRslt = True Then GoTo Result
          End If
        End With
      Next
    Next
  Next
  For Each Shp In .Range.ShapeRange
    With Shp
      If Not .TextFrame Is Nothing Then
        bRslt = FindStyle(.TextFrame.TextRange, Sty)
        If bRslt = True Then GoTo Result
      End If
    End With
  Next
  For Each FtNt In Footnotes
    bRslt = FindStyle(FtNt.Range, Sty)
    If bRslt = True Then GoTo Result
  Next
  For Each E_Nt In Endnotes
    bRslt = FindStyle(E_Nt.Range, Sty)
    If bRslt = True Then GoTo Result
  Next
End With
Result:
If bRslt = True Then StyleInUse = "Y"
End Function
 
Function FindStyle(Rng As Range, Sty As Style) As Boolean
Dim bRslt As Boolean
bRslt = False
With Rng
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = ""
    .Style = Sty.NameLocal
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .Execute
  End With
  If .Find.Found Then FindStyle = True
End With
End Function
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
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 10:35 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