View Single Post
 
Old 10-03-2018, 02:04 PM
MauiTruss MauiTruss is offline Windows 7 64bit Office 2016
Novice
 
Join Date: Oct 2018
Posts: 4
MauiTruss is on a distinguished road
Default Macro to select multiple sentences that contain a specific word

I am looking to create a macro that will select a line that contains a specific word. Ideally it would select all the occurrences in the whole document at once. The word would always be the same so no need for a prompt. I got started but am not sure if I a headed in the right direction. I am pretty lost when it comes to VBA. Any help would be greatly appreciated.

Sub AdjustText()
'
' AdjustText Macro
'
'
Dim myRange As Range
Set myRange = ActiveDocument.Range
With myRange.Find
.text = "Word"
.Replacement.text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
If .Found Then
Selection.Extend
Selection.Extend
Selection.Extend
End If
End With
End Sub
Reply With Quote