Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 08-01-2014, 02:28 AM
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

Since the only Styles you can delete from a document are user-defined Styles that aren't linked, I'm not sure that a macro that doesn't differentiate between these and unused built-in or linked user-defined Styles will be of much use.

The following macro takes a different approach, automatically deleting any unused unlinked user-defined Styles. Although this will save you the effort of manually deleting the un used Styles that can be deleted, it will still take some time to do all its processing.
Code:
Sub DeleteUnusedStyles()
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)
      If .BuiltIn = False And .Linked = False Then
        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 .Delete
      End If
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



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 06:30 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