Return line of text iteratively

Z

Zac Hamilton

Hi All,

I'm having a hard time breaking through this barrier. I need to iteratively
go through the word documnet and pull each line individually from beginning
to end. Right now I'm just trying to write each line of text to the
debugger just to see if it'll work.

I'd really appreciate an example or some helpful pointers.

Thanks,

Zac
 
J

JGM

Hi Zac,

Try something like:

Dim MyRange As Range
Dim MyDoc As Document
Dim AtEnd As Boolean

AtEnd = False

Set MyDoc = ActiveDocument

Selection.HomeKey wdStory

Do While Not AtEnd
Set MyRange = MyDoc.Bookmarks("\Line").Range
If MyRange.End + 1 = MyDoc.Range.End Then AtEnd = True
'Do someting with the line, like:
MyRange.Bold = True
If AtEnd Then Exit Sub
Selection.HomeKey wdLine
Selection.MoveDown wdLine, 1
Loop

HTH
Cheers!
 
Z

Zac Hamilton

Great thx! Works perfectly

-Zac

JGM said:
Hi Zac,

Try something like:

Dim MyRange As Range
Dim MyDoc As Document
Dim AtEnd As Boolean

AtEnd = False

Set MyDoc = ActiveDocument

Selection.HomeKey wdStory

Do While Not AtEnd
Set MyRange = MyDoc.Bookmarks("\Line").Range
If MyRange.End + 1 = MyDoc.Range.End Then AtEnd = True
'Do someting with the line, like:
MyRange.Bold = True
If AtEnd Then Exit Sub
Selection.HomeKey wdLine
Selection.MoveDown wdLine, 1
Loop

HTH
Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top