A
andreas
Dear Experts:
below code is supposed to replace redundant spaces with tabstops just
within the selected paragraphs. Regrettably all the redundant spaces
within the whole document get worked on.
How has the code to be changed to work only on the selection (the
selection for example could be only just one paragraph).
Help is much appreciated. Thank you very much in advance.
Regards, Andreas
Sub SearchAndReplaceJustinSelectedParagraphs()
Dim intcount As Long
Dim myRange As Range
intcount = 0
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Set myRange = Selection.Range
myRange.Select
With myRange.Find
..Forward = True
.Wrap = wdFindContinue
.ClearFormatting
.Text = " {2;}"
.Replacement.Text = "^t"
.MatchWildcards = True
While .Execute(Replace:=wdReplaceOne)
myRange.Collapse wdCollapseEnd
intcount = intcount + 1
Wend
End With
MsgBox intcount
End Sub
below code is supposed to replace redundant spaces with tabstops just
within the selected paragraphs. Regrettably all the redundant spaces
within the whole document get worked on.
How has the code to be changed to work only on the selection (the
selection for example could be only just one paragraph).
Help is much appreciated. Thank you very much in advance.
Regards, Andreas
Sub SearchAndReplaceJustinSelectedParagraphs()
Dim intcount As Long
Dim myRange As Range
intcount = 0
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Set myRange = Selection.Range
myRange.Select
With myRange.Find
..Forward = True
.Wrap = wdFindContinue
.ClearFormatting
.Text = " {2;}"
.Replacement.Text = "^t"
.MatchWildcards = True
While .Execute(Replace:=wdReplaceOne)
myRange.Collapse wdCollapseEnd
intcount = intcount + 1
Wend
End With
MsgBox intcount
End Sub