?
Solved

reading word document line by line

Posted on 2001-06-13
6
Medium Priority
?
157 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 80 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

770 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