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