View Single Post
 
Old 12-04-2017, 08:55 AM
slaycock slaycock is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

I have experienced a similar problem in the past. It is possible to delete linked styles but first you have to unlink the underlying paragraph and character styles.

This is the code I used to do brute force unlinking as I don't allow the use of linked styles in my documents. IMHO they are an abomination, especially from a VBA perspective.

Code:
Sub sbUnLinkAllParagraphCharStyles()
' The enumeration for .type lies.  So it is necessary to check if a paragraph style is linked as .type never returns
' wdStyleParagraphLinked as a value
'
Dim WordStyle                     As Style
    
    log "sbUnLinkAllParagraphCharStyles"
    
    For Each WordStyle In ActiveDocument.Styles
        If WordStyle.Type = wdStyleTypeParagraph Then
            With WordStyle
                If .Linked Then
                    .LinkStyle = ActiveDocument.Styles(wdStyleNormal)
                    ActiveDocument.Styles(WordStyle & " Char").Delete
                End If
            End With
        End If
    Next
End Sub
I hope this points you in the right direction.

Another point to realise is that you cannot use the 'inuse' flag to determine if a style is in use or not. This flag just remembers if in that document the style has ever been used not what the current status is.

To correctly delete unused styles in the manner you wish you have to search the document for an actual occurrence of the style in the list of document styles and then if not found you can delete it with the caveats discussed in the thread above.
Reply With Quote