Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-11-2016, 08:22 AM
Grasor Grasor is offline Move Insertion Point with VBA Windows 7 64bit Move Insertion Point with VBA Office 2013
Novice
Move Insertion Point with VBA
 
Join Date: Jun 2015
Posts: 4
Grasor is on a distinguished road
Default Move Insertion Point with VBA

Hello All,



I'm new to using VBA in Word and am trying to just learn how to navigate a document and interact with content at a referenced position.

My current task is to move the cursor around the document and have the window scroll to the position of the cursor.

Here is what I'm using right now.

Code:
Sub MoveCursor()

Dim lStart As Long
 

lStart = Selection.Start ‘Returns Cursor’s Current Position

Selection.Goto(0) ‘Move Cursor (and scrolls Window) to top of document.

Selection.Start = lStart ‘Move’s Cursor, but does NOT scroll window. To position.


End Sub


The window scrolls to the top of the document on the .Goto(0) method but doesn't when I set Selection.Start = lStart

How can I make the window scroll to the cursor's position?

Thanks,
G
Reply With Quote
  #2  
Old 10-11-2016, 02:37 PM
Guessed's Avatar
Guessed Guessed is offline Move Insertion Point with VBA Windows 10 Move Insertion Point with VBA Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Try
ActiveWindow.ScrollIntoView Selection.Range, True
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 10-11-2016, 08:50 PM
gmayor's Avatar
gmayor gmayor is offline Move Insertion Point with VBA Windows 10 Move Insertion Point with VBA Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

It is not clear why you are scrolling or moving the insertion point, neither of which are necessary to interact with Word.

Investigate ranges. You don't have to select a range in order to work with it, you just have to identify the range to the macro and address it in the code.

You might find http://gregmaxey.com/word_tip_pages/vba_basics.html useful and there are lots of code examples available from the internet, including from my web site.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Text from Insertion Point to Found Text feenyman99 Word 0 04-17-2016 05:40 PM
Word 2013 Insertion Point stops blinking NeilSC Word 0 12-13-2013 12:19 PM
Move Insertion Point with VBA Insertion point not working pmahoney14 Word 1 05-24-2012 04:17 PM
Mapping in Word - Point to Point Directions unistate Word 0 08-08-2011 10:04 AM
Move Insertion Point with VBA wildly flashing insertion point with spinning wheel joannetk Word 4 03-10-2011 04:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:30 AM.


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