Solved

reading word document line by line

Posted on 2001-06-13
6
151 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now