View Single Post
 
Old 03-04-2024, 09:17 AM
Shelley Lou Shelley Lou is offline Windows 10 Office 2016
Expert
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Adding missing Punctuation to end of Paragraphs

Hi Andrew, that is an excellent idea of looking for the duplication instances after the code has run. The below looks for instances of ;]; or .]. and removes the duplicate punctuation after the square bracket to be ;] or .] - this works well but only if the square bracket is not within a text form field. I'm not sure what to add to the code to look for if the square bracket is within a text form field.

Code:
Sub RemovePuncDemo1()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchWildcards = True
    .text = "([;.])([\]])([;.])"
    .Replacement.text = "\1\2"
    .Execute Replace:=wdReplaceAll
    End With
End Sub
Capture.JPG
Reply With Quote