Word does not contain a "Line" object. The Selection object of the Word
application contains a "measurement" Unit of wdLine, but it's not available
to the Range object. The following code opens a document, and then moves
line by line using the Selection object. The text of each line is set into
a string that you can manipulate; here, it's printed to the Immediate
window. Note that you will have to set up strDoc - the file path and name
of your Word doc - for yourself.
HTH
Ed
Sub TestReadWord()
Dim appWD As Word.Application
Dim docWD As Word.Document
Dim rngWD As Word.Range
Dim strDoc As String
Dim strLine As String
Dim bolEOF As Boolean
bolEOF = False
' Set strDoc here to include the full
' file path and file name
On Error Resume Next
Set appWD = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set appWD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0
Set docWD = appWD.Documents.Open(strDoc)
appWD.Visible = True
docWD.Characters(1).Select
Do
appWD.Selection.MoveEnd Unit:=wdLine, Count:=1
strLine = appWD.Selection.Text
Debug.Print strLine
appWD.Selection.Collapse wdCollapseEnd
If appWD.Selection.Bookmarks.Exists("\EndOfDoc") Then bolEOF = True
Loop Until bolEOF = True
docWD.Close wdDoNotSaveChanges
Set docWD = Nothing
appWD.Quit
Set appWD = Nothing
End Sub
"ExcelPower" wrote
in message ...
I want to read Ms Word file line by line. Is there any way other than
Paragraph & Word to select range. Can i select range in MS word line by
line.
for eg. inplace of following code can i use "Line" in place of
"paragraph"????
'**********
with MSWD
'Set trange = .Range(Start:=.Paragraphs(3).Range.Start,
End:=.Paragraphs(3).Range.End)
end with
'**************
if not tell me how Ms word recognises When Paragraph has started &
when ended????
I am really willing to know
thanks in advance
With Regards
Excel Power
--
ExcelPower
------------------------------------------------------------------------
ExcelPower's Profile:
http://www.excelforum.com/member.php...o&userid=30964
View this thread: http://www.excelforum.com/showthread...hreadid=514832