![]() |
#2
|
||||
|
||||
![]()
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
shmu | Misc | 4 | 02-18-2014 12:34 AM |
![]() |
OTPM | Project | 4 | 08-22-2013 01:33 PM |
Need Macro code for Outlook | gbaker | Outlook | 0 | 04-11-2013 10:29 AM |
![]() |
chefmate | Excel Programming | 1 | 08-26-2012 01:04 AM |
Macro to Table Style | ubns | Word VBA | 1 | 04-16-2012 05:01 AM |