Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2006

Tip: Looking for answers? Try searching our database.

How to Read the MS Word file line by line - urgent

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SpiderSwamy - 09 Mar 2006 06:06 GMT
Hi plz, tell me how to read MS Word file line by line.
I am able to open the file using the following code.

code:

Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objTbl As Word.Table

Set objWord = New Word.Application
objWord.Documents.Add
objWord.Visible = True
Set objDoc = objWord.ActiveDocument
Call objWord.Documents.Open(sFilepath, , True, True)
SpiderSwamy - 09 Mar 2006 06:22 GMT
This need to done in VB6. anyone who knows it plz, reply it will be
very help ful..
Charles Kenyon - 09 Mar 2006 06:28 GMT
Hello,

You need to learn Word before you start programming it.
Word files are not line by line. The concept doesn't make sense in the Word
object model.
If the Word file were to be converted to a text file with a CRLF at the end
of each converted line, you would have something you could do this with I
suppose.

What, exactly, are you trying to do? Why?
Signature

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

> Hi plz, tell me how to read MS Word file line by line.
> I am able to open the file using the following code.
[quoted text clipped - 10 lines]
> Set objDoc = objWord.ActiveDocument
> Call objWord.Documents.Open(sFilepath, , True, True)
SpiderSwamy - 09 Mar 2006 06:40 GMT
Hi,

    i am writing a program in VB6 where i need to search for a keyword
line by line i have done it for .txt file.

If you provide me the code from which Word file were converted to a
text file. it would be a great help.

Thanks in Advance
Jonathan West - 09 Mar 2006 06:54 GMT
> Hi,
>
[quoted text clipped - 5 lines]
>
> Thanks in Advance

The following code will put the whole of the unformatted text of the
document (excluding headers footers and textboxes) into the string variable
strText. You can then do whatever you want with that variable.

Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim strText as String

Set objWord = New Word.Application
objWord.Visible = True
Set objDoc = objWord.Documents.Open(sFilepath, , True, True)
strText = objDoc.Content.Text

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

SpiderSwamy - 09 Mar 2006 09:33 GMT
Hi,
in test.doc I have the following text.

User Prabhakar
Optiva search
Test this is for test

using this code :

Set objWord = New Word.Application
objWord.Visible = True
Set objDoc = objWord.Documents.Open(sFilepath, , True, True)
strText = objDoc.Content.Text

strText = "User Prabhakar Optiva search Test this is for test"

then I am using  IntSplitArray = Split(strText, , -1, 1) then getting
the following

   :  IntSplitArray(0) : "User" : String : Form2.Find
   :  IntSplitArray(1) : "Prabhakar Optiva" : String : Form2.Find
   :  IntSplitArray(2) : "search Test" : String : Form2.Find
   :  IntSplitArray(3) : "this" : String : Form2.Find
   :  IntSplitArray(5) : "for" : String : Form2.Find
   :  IntSplitArray(6) : "test" : String : Form2.Find

what function can i use to get it like

   :  IntSplitArray(0) : "User Prabhakar " : String : Form2.Find
   :  IntSplitArray(1) : "Optiva search" : String : Form2.Find
   :  IntSplitArray(3) : "Test this is for test" : String : Form2.Find
Jonathan West - 09 Mar 2006 09:50 GMT
Use the following line

IntSplitArray = Split(strText, vbCrLf, -1, 1)

This will split the text by paragraph.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

> Hi,
> in test.doc I have the following text.
[quoted text clipped - 27 lines]
>    :  IntSplitArray(1) : "Optiva search" : String : Form2.Find
>    :  IntSplitArray(3) : "Test this is for test" : String : Form2.Find
Oliver Townshend - 09 Mar 2006 09:51 GMT
> in test.doc I have the following text.
>
> User Prabhakar
> Optiva search
> Test this is for test

Are these separate paragraphs?  What if you had a line that word-wrapped?

Is the purpose of the search to say "Hey the word appears on line 6, 5th
word?"  Or to act upon the words you find?

Oliver Townshend
SpiderSwamy - 09 Mar 2006 10:19 GMT
> in test.doc I have the following text.

> User Prabhakar
> Optiva search
> Test this is for test

these 3 are lines one next to another not paragraphs..

and when i find "Optiva" i need do display "search" or till end of line
after Optiva keyword.

the code:
IntSplitArray = Split(strText, vbCrLf, -1, 1)

is not making the difference its displaying the content in a single
line.
its giving the following output..

IntSplitArray(0) : "User Prabhakar Optiva search Test this is for test"
Jonathan West - 09 Mar 2006 11:39 GMT
Word doesn't think in terms of lines - lines will wrap where they will and
are dynamically updated according to the page size, margins, font etc. The
location of these automatic line breaks is not stored in the document.

If you really need to find the location of these automatic line breaks, then
it is possible, but complex and not necessarily reliable.

But I get the impression that you are not talking about automatic line
breaks, but rather of text that has been deliberately split into separate
lines. If this is the case, what we need to discover is the character(s)
that are used to separate the lines. The most likely candidates are the
string represented by the VB constant vbCr, which represents a paragraph
break in Word, or Chr$(11), which represents a manual line break (inserted
by pressing Shift-Enter in Word).

Whichever character is being used is the character you need for the
delimiter in the Split function.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

>> in test.doc I have the following text.
>
[quoted text clipped - 15 lines]
>
> IntSplitArray(0) : "User Prabhakar Optiva search Test this is for test"
SpiderSwamy - 09 Mar 2006 12:12 GMT
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim strText As String

Set objWord = New Word.Application
'objWord.Visible = True
Set objDoc = objWord.Documents.Open(sFilepath, , , True)
strText = objDoc.Content.Text
strText = objDoc.Content.Text
readlineword:

objDoc.Close

IntSplitArray = Split(strText, vbCr, -1, 1)

this part of code has workred fine vbCr is the one which is vbCr
Chr(13) Carriage return is used for seperation of lines..

But i am unable to close the WINWORD.EXE which is created by Set
objWord = New Word.Application

I am only able to close the  objDoc.Close( i.e. the test.doc file )

do you know how to close the WINWORD.EXE which is created by Set
objWord = New Word.Application.

plz reply because so many WINWORD.EXE are visible in my process( i.e.
in the task manager)

Thanks
Manju
Jonathan West - 09 Mar 2006 12:28 GMT
> Dim objWord As Word.Application
> Dim objDoc As Word.Document
[quoted text clipped - 24 lines]
> plz reply because so many WINWORD.EXE are visible in my process( i.e.
> in the task manager)

when you are finished with Word, after objDoc.Close, include the following
lines

objWord.Quit SaveChanges:=wdDoNotSaveChanges
Set objWord = Nothing

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org 

SpiderSwamy - 10 Mar 2006 04:54 GMT
Thank you very much man. The code did the magic i was doing only Set
objWord = Nothing. then i saw your code i was great man, i am very much
thankfull to you Jonathan West. you have understanded my problem and
gave me the solution.
Thanks a lot lot lot lot lot lot lot..................
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.