Solved

reading word document line by line

Posted on 2001-06-13
6
153 Views
Last Modified: 2010-05-02
Do you have any sample code or any idea how to read data from a word document -
line by line?

The following code will only read by paragragh
but i need reading line by line(not sentence by sentence)

Dim oWord
Dim vPara As Variant
Dim sLine As String
Dim iFile As Integer

Set oWord = CreateObject("Word.Application")

Call oWord.Documents.Open(App.Path & "\a11.doc")

For Each vPara In oWord.ActiveDocument.Paragraphs
     'Get the Current Paragraph
    sLine = vPara.Range.Text

    ' Remove Paragraph Mark
    sLine = Left(sLine, Len(sLine) - 1)

    MsgBox sLine

   
Next

oWord.Application.ActiveDocument.Close
oWord.Application.Quit
MsgBox "ok"
0
Comment
Question by:hky1026
  • 4
6 Comments
 
LVL 4

Expert Comment

by:mcoop
ID: 6189886
You need to look for soft carriage returns... hmmm
Let me have a look...
0
 
LVL 4

Accepted Solution

by:
mcoop earned 20 total points
ID: 6189910
Interesting...
soft line breaks are not a searchable entity within word from what I can see.

However, you CAN save as text with line breaks - which of course does what you want.

The immediate solution is to force a 'Save As...' operation, using the 'text with line breaks' format.

The you can read back the text file line by line.

I'm still thinking about a way to do it in code - it certainly should be possible.

0
 
LVL 4

Expert Comment

by:mcoop
ID: 6189918
Of course, yo could do it as a select operation...

You could do it as a macro in word, then look at the macro code to get an idea of what you need to do in the word object.

Move to the start of each line, then 'select' to the end of the 'line' (not the para), then copy to clipboard, and pste as text (or RTF if that's what you want).
0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
LVL 4

Expert Comment

by:mcoop
ID: 6189921
pseudocode to do the deed

while not end-of-doc

  Selection.HomeKey Unit:=wdLine
  Selection.EndKey Unit:=wdLine, Extend:=wdExtend
  Selection.Copy
 
  ' paste into your app...
 
  Selection.MoveRight Unit:=wdCharacter, Count:=1

Wend
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7136085
Hi hky1026,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept mcoop's comment(s) as an answer.

hky1026, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7168368
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question