Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 08-02-2014, 09:40 PM
macropod's Avatar
macropod macropod is offline Style in Use Macro-Need Help Optimizing Code Windows 7 32bit Style in Use Macro-Need Help Optimizing Code 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
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Style in Use Macro-Need Help Optimizing Code optimizing computer for MS Office shmu Misc 4 02-18-2014 12:34 AM
Style in Use Macro-Need Help Optimizing Code VBA Code for adding Macro to QAT OTPM Project 4 08-22-2013 01:33 PM
Need Macro code for Outlook gbaker Outlook 0 04-11-2013 10:29 AM
Style in Use Macro-Need Help Optimizing Code I need help with macro...code needed for automatic sorting chefmate Excel Programming 1 08-26-2012 01:04 AM
Macro to Table Style ubns Word VBA 1 04-16-2012 05:01 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:03 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