Preserve the initial scope of a selection on a search operation andre-use it later

A

andreas

Dear Experts:

For some specific reasons I am using the Selection Object for a search
operation.

below macro searches for two or more consecutive tab stops. The
trouble is, if an occurrence of two consecutive tab stops is found the
initial selection is reduced to the length of the first occurrence.

Is it possible to preserve the initial selection and re-activate it
after the first occurrence of two or more consecutive tab stops?

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^t{2;}"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
End With
Selection.Find.Execute
If Selection.Find.Found Then
If MsgBox("Consecutive Tab Stops found! Would you like to
continue?", vbCritical, "Consectutive Tab Stops found!") = vbNo Then
Exit Sub
End If
Else .... (The initial selection should be re-activated)
 
J

Jay Freedman

Before the "With Selection.Find" statement, define a Range object that
will store the original Selection's location:

Dim myRange As Range
Set myRange = Selection.Range

At the end of the code you showed, select that Range object:

mYRange.Select

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
A

andreas

Before the "With Selection.Find" statement, define a Range object that
will store the original Selection's location:

Dim myRange As Range
Set myRange = Selection.Range

At the end of the code you showed, select that Range object:

mYRange.Select

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ:http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.









- Zitierten Text anzeigen -

Hi Jay,

that's it. Thank you very much for your professional help.

Regards, Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top