View Single Post
 
Old 10-09-2020, 02:47 AM
alex100 alex100 is offline Windows 7 64bit Office 2016
Advanced Beginner
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default Finding text without moving the cursor down

I am using the following code in a larger Word macro that I use...

Code:
With Selection.Find
    .ClearFormatting
    .Text = "http" & "*" & vbCr & "-----"
    .MatchWildcards = True
    .MatchWholeWord = True
    Do While .Execute
        Selection.MoveStart Unit:=wdCharacter, Count:=0
        Selection.MoveEnd Unit:=wdCharacter, Count:=-6
    Loop
End With
url = Selection.Text
It finds and saves (in a variable) the first URL address that is written in this particular format:

http:// www.address.com
-----

The problem is that the code moves down the page (depending on where an URL address is found), and the current page view goes out of focus.

How can I avoid this? What I need is to keep the same functionality of the code, but achive this in a seamless way, without moving the cursor at all.

Using 'Application.ScreenUpdating = False' does seem to help, but the page still loses its initial position when the code is run. I also tried saving the vertical scroll position and restore it later (using 'ActiveWindow.ActivePane.VerticalPercentScrolled') . That helped too, but did not solve the problem entirely.

Alex
Reply With Quote