Solved

reading word document line by line

Posted on 2001-06-13
6
154 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

861 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