+ Reply to Thread
Results 1 to 3 of 3

How to read a line from Ms Word

  1. #1
    Registered User
    Join Date
    01-30-2006
    Posts
    30

    Arrow How to read a line from Ms Word

    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

  2. #2
    Ed
    Guest

    Re: How to read a line from Ms Word

    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" <[email protected]> wrote
    in message news:[email protected]...
    >
    > 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
    >




  3. #3
    Registered User
    Join Date
    01-30-2006
    Posts
    30

    Smile Thanks

    thanks Ed this works great
    one more thing your style of communication is clear & clean- keep helping

    bye

    thanks again

    with regards

    Excel Power

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1