View Single Post
 
Old 08-02-2014, 09:40 PM
macropod's Avatar
macropod macropod is online now Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,384
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

As indicated in my previous post, with that macro you can't delete linked Styles or Styles that are in use, so it seems that, apart from deleting as opposed to merely hiding Styles, it does what you want. To merely hide the unused Styles instead of deleting them, regarless of whether they're built-in or linked, you could use:
Code:
Sub HideUnusedStyles()
Dim Doc As Document, bDel As Boolean
Dim Rng As Range, StlNm As String, i As Long
Application.ScreenUpdating = False
On Error Resume Next
Set Doc = ActiveDocument
With Doc
  For i = .Styles.Count To 1 Step -1
    With .Styles(i)
        bDel = True: StlNm = .NameLocal
        For Each Rng In Doc.StoryRanges
          With Rng
            With .Find
              .ClearFormatting
              .Format = True
              .Style = StlNm
              .Execute
            End With
            If .Find.Found = True Then
              bDel = False
              Exit For
            End If
          End With
        Next
        If bDel = True Then .Visibility = False
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
The only material difference between this sub and the previous one is that I've omitted the 'If .BuiltIn = False And .Linked = False Then' test and I've changed:
.Delete
to:
.Visibility = False
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote