I have created a macro to help me when formatting documents. The code finds instances of rogue punctuation, mostly ones that are bold and highlights them bright green so I can easily identify what I need to reformat in line with housestyle. I've got the code to also not highlight bold punctuation if contained within a bold heading or part of a bold definition through the IF Statement.
I'm struggling of what to add to the IF Statement to capture other instances e.g. more than one bold punctuation together (see 1.8 of the attached document where I've listed a few examples). Would appreciate any advice.
Bold Punc but not within Bold Text.docx
Code:
Sub HighlightBoldPuncDemo1()
Application.ScreenUpdating = False
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Highlight = True 'Activate replacement highlighting
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
Options.DefaultHighlightColorIndex = wdBrightGreen
.text = Chr(34) 'Highlight non-bold straight quotes
.Font.Bold = False
.Execute Replace:=wdReplaceAll
.text = "[[\]^0145^0146^0147^0148]{1,}" 'Highlight non bold curly quotes/apostrophes/square brackets
.Execute Replace:=wdReplaceAll
.text = "[" & Chr(44) & Chr(145) & Chr(146) & Chr(147) & Chr(148) & "\(\)\[\]\:\;\.\'\,]" 'Highlight bold curly quotes/apostrophes, brackets/square brackets, comma etc.
.Font.Bold = True
.Execute Replace:=wdReplaceAll
End With
With oRng.Find
.text = "[" & Chr(34) & "\(\)\[\]\:\;\.\'\,]" 'highlight bold straight quotes if word is plain text but don't highlight if all bold
.Font.Bold = True
While .Execute
oRng.Select
On Error Resume Next
If oRng.Characters.Last.Next.Font.Bold = False Then oRng.HighlightColorIndex = wdBrightGreen 'highlight if bold but not within a heading or definition
If oRng.Characters.Last.Previous.Font.Bold = True Then oRng.HighlightColorIndex = wdNoHighlight 'don't highlight if contained within a bold heading
Wend
End With
End Sub