View Single Post
 
Old 05-27-2021, 12:47 PM
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 semi colon at end of sentences

Hi, I have got the macro below to insert semi-colons at the end of a sentence. I'm looking to exclude certain words at the end of sentence i.e 'and, but and or' as these belong to lists which already have a semi-colon before each of these words. How can I exclude these in the code. Thanks


Code:
Sub DPU_Test()
Application.ScreenUpdating = False
Dim Para As Paragraph
Dim oRng As Range
Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = ".^p"
    .Replacement.Text = "^p"
    .Execute Replace:=wdReplaceAll
    End With
On Error Resume Next
For Each Para In ActiveDocument.Paragraphs
With Para.Range
If Len(.Text) > 2 Then
If Not .Characters.Last.Previous Like "[.!?:;]" Then
.Characters.Last.InsertBefore ";"
End If
End If
End With
Next
Application.ScreenUpdating = True

End Sub
Reply With Quote