![]() |
|
|
|
#1
|
||||
|
||||
|
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
Code:
Select Case .InUse
Case False: StrAttr = StrAttr & "N"
Case Else: StrAttr = StrAttr & StyleInUse(ActiveDocument, Sty)
End Select
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] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Font list character display
|
whabtewo | Word | 1 | 03-09-2014 08:12 PM |
MAcro to List all the Font & its size in a word document
|
shaukat74 | Word VBA | 1 | 01-29-2013 09:34 PM |
Restricting paragraph styles without restricting character styles
|
Red Pill | Word | 5 | 05-25-2012 01:06 PM |
Quick Styles Set saved but it doesnt appear at the styles list!
|
Pedro77 | Word | 3 | 10-15-2011 05:17 AM |
The list of styles appears in different way in different document?????
|
Jamal NUMAN | Word | 4 | 04-28-2011 05:40 AM |