Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-18-2015, 09:50 PM
anand anand is offline changing cursor position Windows 7 64bit changing cursor position Office 2010 32bit
Novice
changing cursor position
 
Join Date: Jun 2015
Posts: 15
anand is on a distinguished road
Default changing cursor position

I am running a loop to check starting character of each line. while doing this i require that current cursor position also moves to starting letter of each line.


Can anyone suggest me the VBA code in Word which also changes cursor position as loop executes.
Reply With Quote
  #2  
Old 06-19-2015, 01:19 AM
gmayor's Avatar
gmayor gmayor is offline changing cursor position Windows 7 64bit changing cursor position Office 2010 32bit
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

What exactly are you trying to check and why?
What do you mean by a 'line'. Lines in Word are volatile entities created by text flow. Do you perhaps mean 'paragraph'?
There is no reason to 'move the cursor, to establish what the first character of a paragraph is, but if you insist, the following will work for the document body.

Code:
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
    oPara.Range.Characters(1).Select
    MsgBox oPara.Range.Characters(1)
Next oPara
__________________
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
  #3  
Old 06-19-2015, 05:18 AM
gmaxey gmaxey is offline changing cursor position Windows 7 32bit changing cursor position Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
  Selection.HomeKey Unit:=wdStory
  Do
    Selection.EndKey Unit:=wdLine
    If Selection.End >= ActiveDocument.Content.End - 1 Then
      Exit Do
    End If
    Set oRng = ActiveDocument.Bookmarks("\Line").Range
    With oRng
      .Collapse wdCollapseStart
      .MoveEnd wdCharacter, 1
      .Select
      'Do something with oRng
    End With
    Selection.MoveDown Unit:=wdLine
  Loop
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Increase Sentence Font at cursor position ilcaa72 Word VBA 8 02-20-2014 08:40 AM
changing cursor position Changing Cursor display? savo Excel 1 02-16-2014 07:39 PM
changing cursor position Add multiple rows to Excel 2010 table at cursor position C J Squibb Excel Programming 12 11-07-2013 07:35 AM
Displaying cursor position within cell MiamiTom Excel 0 11-18-2011 09:02 AM
Retrieve position of Cursor - x & y positions SDondeti PowerPoint 0 05-19-2011 11:39 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:14 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