Selecting text from a word file

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi
Im using VB (visual studio) 2008. Im trying to search a microsoft word file and select/copy text from it
What i want to do
a. Search for a string/word in a text document(i.e "question)
b. When its found copy of text from that point to a point further down the document defined by a certain string ("a.")
c. after this is done it will continue to look for the next time the same string occurs (i.e. "question"") and continue as above

This is to search a question paper and separate the questions out and save it separately .
Ive figured out how to search for the word (question) but not managed to figure out the rest of it. Heres the code so far
Dim oWord As Word.Application = CreateObject("Word.Application")<br/>
Dim wdword As Word.Range<br/>
Create new word document<br/>
<br/>
Dim oDoc As Word.Document = oWord.Documents.Open("test.doc")<br/>
<br/>
oWord.Visible = True<br/>
oDoc.Range.Copy()richi.SelectAll()richi.Paste()<br/>
For Each wdword In oDoc.Words<br/>
If wdword.Text = "Question" Then<br/>
Ãode to select text from this point till string "a." found<br/>
End If<br/>
Next<br/>
oDoc.Close()
<br/>

View the full article
 
Back
Top