Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-09-2020, 02:47 AM
alex100 alex100 is offline Finding text without moving the cursor down Windows 7 64bit Finding text without moving the cursor down Office 2016
Advanced Beginner
Finding text without moving the cursor down
 
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
 



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
Finding text without moving the cursor down 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 text without moving the cursor down Finding the nth Blank Value in a Row of Text ljg713 Excel 7 01-12-2016 07:49 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:15 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft