View Single Post
 
Old 11-20-2018, 04:01 AM
yolandal yolandal is offline Windows 10 Office 2019
Novice
 
Join Date: Nov 2018
Posts: 2
yolandal is on a distinguished road
Question How can I combine the code for Search + Replace?

Hi there,
For certain documents I'm using this code to make automatisch Search + Replace, but the code is getting very long.
Is there a way to combine, strip or trim this code, as most of it is the same for every change?

In that case I will have a better view of what I'm doing, instead of a code with 2000+ rules.

Thank you for your time.

Yolanda





Sub Ams1()
'
' Ams1 Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

End Sub
Reply With Quote