I have the following script that will find a period followed by 2 or more spaces, but what I’m looking for is to be able to find the first word of a sentence and if it’s “Medical” then it will change it. I was hoping to capitalize off of this script but I can already tell if it’s the first word of a paragraph it’ll be missed, and I’m not sure how to have it search properly for “. Medical”
With Selection.Find
.ClearFormatting
.Highlight = False
.Replacement.ClearFormatting
.Replacement.Highlight = True
.Text = (\.)( {2,9})
.Replacement.Text = "\1 "
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
I ended up finding another post at link and came up with this:
Dim i As Integer
Dim doc As Document
Set doc = ActiveDocument
For i = 1 To doc.Sentences.Count
If doc.Sentences(i).Words(1) = "Medical " Then
doc.Sentences(i).Words(1) = "Medical (needs removal) "
End If
If doc.Sentences(i).Words(1) = "Dental " Then
doc.Sentences(i).Words(1) = "Dental (needs removal) "
End If
If doc.Sentences(i).Words(1) = "Life " Then
doc.Sentences(i).Words(1) = "Life (needs removal) "
End If
If doc.Sentences(i).Words(1) = "Vision " Then
doc.Sentences(i).Words(1) = "Vision (needs removal) "
End If
Next
Here’s a snippet from that code block:
XX = Whatever you want to change the word Medical to.
(\. )matches the end of a sentence.( )+matches extraneous spaces.This should both fix your multiple spaces issue and change Medical to whatever you want.
I have not tested this. Please use discretion.