Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-11-2014, 08:38 AM
ilcaa72 ilcaa72 is offline Loop through each Line in Word Windows 7 64bit Loop through each Line in Word Office 2010 64bit
Novice
Loop through each Line in Word
 
Join Date: Jan 2014
Posts: 27
ilcaa72 is on a distinguished road
Default Loop through each Line in Word

hi, i have a looping action for each Sentence and for each paragraph. But i would like to loop through each Line. is this possible?

Code:
Public Sub ParseLines()
    'SPLIT BY PARAGRAPHS
    Dim singleLine As Paragraph
    Dim lineText As String

    For Each singleLine In ActiveDocument.Paragraphs
        lineText = singleLine.Range.Text

        MsgBox lineText

    Next singleLine
End Sub

Reply With Quote
  #2  
Old 02-11-2014, 11:07 PM
macropod's Avatar
macropod macropod is offline Loop through each Line in Word Windows 7 32bit Loop through each Line in Word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Being a word processor, Word doesn't really work in lines, then length and content of which can vary as a result of nothing more complicated than a change in the active printer. There are exceptions, of course, such as when lines are terminated by manual line breaks but even they can be affected by a change in the active printer (e.g. what was already the last of 10 words on a line before the manual line break might become the only word on that line). That's why paragraphs don't have a Line property. If you explain what you're trying to achieve, perhaps we can advise on how you might do so.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-12-2014, 08:12 AM
gmaxey gmaxey is offline Loop through each Line in Word Windows 7 32bit Loop through each Line in Word Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
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

I'm not intending to dispute Paul's reply. Word doesn't really work with lines.

There are however some methods and properties associated with the activewindow object that you might use. For example, using the following code, you can scroll through a document one line at a time:

Code:
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private bStop As Boolean
Sub StopScroll()
bStop = True
End Sub
Sub StartScroll()
Dim i As Long
Dim oPage As Page
Dim j As Long
Dim oRng As Word.Range
  bStop = False
  For Each oPage In ActiveDocument.ActiveWindow.ActivePane.Pages
    For i = 1 To oPage.Rectangles(1).Lines.Count
      j = oPage.Rectangles(1).Lines(i).Range.HighlightColorIndex
      oPage.Rectangles(1).Lines(i).Range.Select
      Set oRng = Selection.Range
      Selection.Collapse wdCollapseEnd
      oRng.HighlightColorIndex = wdYellow
      Doze 200 '= 1 second
      DoEvents
      ActiveDocument.ActiveWindow.SmallScroll Down:=1 'one line
      oRng.HighlightColorIndex = j
      Application.ScreenRefresh
      If bStop Then GoTo lbl_Exit
    Next i
  Next oPage
lbl_Exit:
  Exit Sub
End Sub
Sub Doze(ByVal lngPeriod As Long)
    DoEvents
    Sleep lngPeriod
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 02-13-2014, 09:25 AM
ilcaa72 ilcaa72 is offline Loop through each Line in Word Windows 7 64bit Loop through each Line in Word Office 2010 64bit
Novice
Loop through each Line in Word
 
Join Date: Jan 2014
Posts: 27
ilcaa72 is on a distinguished road
Default

thanks for the script, ill tweak it and see if I can use it....

I figured I could loop "lines" and then do what i want with them since there are some basic functions Word provides that deal with lines, (line numbering)

i am working on parsing text within Word for the internet so creating a cleanup program based on my personal needs (i have seen many clean up macros out there, they are great but dont fit for my needs)

so i would like to isolate some "lines" that contain certain objects or formatting that I cant isolate with looping each "sentence".

Could I loop each "line-breaks"?

this is 1 example. I parsed sentences and this is the last word of the sentence and ended up in its own line. When I looked into it, it contains these 2 symbols. What are they whats their meaning in Word? (pic enclosed)
Attached Images
File Type: jpg WordError.jpg (253.4 KB, 48 views)
Reply With Quote
  #5  
Old 02-13-2014, 11:48 AM
macropod's Avatar
macropod macropod is offline Loop through each Line in Word Windows 7 32bit Loop through each Line in Word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The ↵ characters in your document are manual line breaks. You can find them using:
Find = ^l

For another 'cleanup' macro, try the one here: https://www.msofficeforums.com/word/...html#post32907. Although you say the ones you've tried don't do what you want, you haven't said what you see as their failings, so you're not giving yourself much chance of being helped with a solution.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through each Line in Word Loop through Word doc to find and reformat text Sandy27 Word VBA 5 01-06-2014 03:48 PM
Loop through each Line in Word Loop action in Word until not found kilburfi Word VBA 2 07-12-2013 01:26 AM
Loop through each Line in Word How to a For loop in VBA Jennifer Murphy Word VBA 1 01-29-2013 03:30 AM
Loop through each Line in Word Macro to loop in Word Yamaha Rider Word VBA 2 02-07-2012 05:33 PM
Loop through each Line in Word WORD Macro - import picture - resize - position - page break - loop Nano07 Word VBA 2 11-02-2011 05:14 AM

Other Forums: Access Forums

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