
Reading a Word Doc Line by Line in VBA
Quote:
> Does anyone have code that can read in a Microsoft Word Document line by
> line?
Microsoft has (or had, my printout is dated may 10. 1999) a document in the
online Knowledge Base called "WD97: Sample code to increment through a
document line by line"
Something like this has worked for me:
' Move the insertion point to the beginning of the document.
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
' Loop number of lines in document.
x = ActiveDocument.BuiltInDocumentProperties("NUMBER OF LINES")
For i = 1 To x
' Select a line.
ActiveDocument.Bookmarks("\LINE").Select
Indhold = Trim(Selection)
'here you can do whatever you want to the line contained in the var.
Indhold
' Display line number. Just for test reasons, don't do it on your
150.000 lines new book manuscript ;-)
MsgBox "Line: " & i
' Move to next line.
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
Next i
--
Med venlig hilsen / Kind regards
from ?lstykke, Denmark
Kim
home: http://home2.inet.tele.dk/kim-niel/
business: http://viviankisoft.hypermart.net/