View Single Post
 
Old 07-02-2021, 12:59 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 to only remove word at beginning and not additional instances within the same paragraph

I have the following code that removes instances of the word 'means' that follow after the bold definition text. However, the macro also removes any additional word 'means' that may be within the same paragraph as normal text. What can I add to the code that would stop this from happening. Thanks

Remove the word means TEST DOC June 2021.docx

Code:
Sub DefMeans()
Dim aRng As Range, aPara As Paragraph
  Set aRng = ActiveDocument.Range
  For Each aPara In aRng.Paragraphs
  Next aPara
  With aRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "[:;, ^t]{1,5}means[:;, ]{1,5}"
    .Replacement.Text = "^t"
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
End With
End Sub
Reply With Quote