#1
|
|||
|
|||
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 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 |
#2
|
|||
|
|||
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim URL As String Dim oRng As Range Set oRng = ActiveDocument.Range With oRng.Find Selection.ClearFormatting .Text = "http" & "*" & vbCr & "-----" .MatchWildcards = True .MatchWholeWord = True Do While .Execute oRng.End = oRng.End - 6 URL = oRng.Text oRng.Collapse wdCollapseEnd Loop End With MsgBox URL lbl_Exit: Exit Sub End Sub |
#3
|
|||
|
|||
Thank you very much, this is just what I needed!
Alex |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Cursor moving text in blocks, black blocks appear | Gippslander | Word | 2 | 11-06-2018 11:31 PM |
How do I lock an editable text box header and stop it moving with the rest of the main body text? | thegaffa | Word | 6 | 09-28-2018 09:21 AM |
finding 'struck-through' text | joebloggs | Word | 1 | 08-16-2017 10:27 PM |
Selecting and moving text boxes identified by specific text. | Chayes | Word VBA | 8 | 02-22-2016 07:01 AM |
Finding the nth Blank Value in a Row of Text | ljg713 | Excel | 7 | 01-12-2016 07:49 AM |