Solution is doing the Search in ActiveDocument.Range

L

Larry

The solution to this was simply to set the search to
ActiveDocument.Range. That avoids the need of returning the cursor to
the place in the document and returning the document to the same place
in the window where they were when the macro began, because, when the
Search is in ActiveDocumentRange, the cursor and the document don't
move.

I should have know this before, as Jay Freedman showed it to me in a
couple of macros, but I didn't make the connection to this other
problem. In fact, I still had a bunch of macros that searched in
Selection.Range instead of ActiveDocument.Range, and I didn't realize
until now the different results of those two methods.

Larry
 
L

Larry

Of course, simply doing a Find and setting it to Wrap wdContinue will
leave the document and cursor in the same position. But that's not the
case in more complicated macros, say some macros that have a Do While
operation going in the middle of the Search operation. Macros like that
will leave the selection somewhere else, like at the bottom of the page.
But using ActiveDocument.Range for the search will leave the selection
where it started.

Larry
 

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