Hello everyone,
I want to find and replace certain word in selected range of text only,
Also, if I don't select anything, a message appear "Please select the range first", in order to prevent find and replace on entire document by mistake.
Code:
Sub ReplaceName()
'
'Find what Format:
Selection.Find.ClearFormatting
' Replace with Format:
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Jhon"
.Replacement.Text = "Robert"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Thank you