Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 11-29-2017, 09:14 PM
macropod's Avatar
macropod macropod is offline Macro that deletes unused styles Windows 7 64bit Macro that deletes unused styles Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,514
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

Try:
Code:
Sub DeleteUnusedStyles()
Dim Doc As Document, Rng As Range, Shp As Shape
Dim StlNm As String, i As Long, bDel As Boolean
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.Find
            .ClearFormatting
            .Format = True
            .Style = StlNm
            .Execute
            If .Found = True Then
              bDel = False
              Exit For
            End If
          End With
          For Each Shp In Rng.ShapeRange
            If Not Shp.TextFrame Is Nothing Then
              With Shp.TextFrame.TextRange.Find
                .ClearFormatting
                .Format = True
                .Style = StlNm
                .Execute
                If .Found = True Then
                  bDel = False
                  Exit For
                End If
              End With
            End If
          Next
        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]
Reply With Quote
 

Tags
delete unused, macro, styles



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete unused cell remaining at end of a block of deleted data SKEETER Excel 2 10-24-2017 07:06 AM
Macro that deletes unused styles Macro to Import Styles John9210 Word VBA 1 02-06-2015 04:47 PM
Remove unused bottom white space. johnatanasoff Word 4 11-05-2014 06:07 PM
transfering outlook PST to a new pc, unused storage folder and suggested contacts burgers Outlook 1 06-14-2011 04:05 PM
Unused to Outlook need to save folders - help? franontheedge Outlook 0 10-31-2007 07:47 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:21 PM.


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