Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

reading word document line by line

Posted on 2001-06-13
6
Medium Priority
?
160 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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

636 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