My job involves processing many large files daily. Each large file contains over 1500 pages, and within each document, there is an abundance of custom styles that are not in use. Nearly every file has about 500-600 unused custom styles. I use the following code to remove these custom, unused styles, which requires iterating through all the document’s styles, excluding the built-in ones, and then searching for these styles throughout the content of all documents. It is important to note that VBA does not support multithreading. The lack of multithreading support greatly reduces efficiency. My question is, apart from the code below, are there any more efficient algorithms to solve this problem?
Sub DeleteUnusedStyles()
On Error Resume Next
Dim oStyle As style, count
For Each oStyle In ActiveDocument.styles
If oStyle.BuiltIn = False Then
With ActiveDocument.Content.Find
.ClearFormatting
.style = CVar(oStyle.NameLocal)
.Execute FindText:="", Format:=True
If.Found = False Then
oStyle.Delete
End If
End With
End If
Next oStyle
End Sub