473,322 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Found Text but Can't Extract from Word Doc

I've got the code to search through a directory for word documents,
open the doc, search for specific text... but I'm trying to extract
data that immediately follows the selected highlighted text. I can't
figure out the correct syntax to give me the text that follows the
currently selected text. Here is my code:

Set objword = New Word.Application
objword.Documents.Add "filename.doc"
objword.WindowState = wdWindowStateMaximize
objword.Visible = True
With objword.Selection
Do
.Find.Text = "Purpose:"
.Find.Forward = True
.Find.Wrap = wdFindStop
.Find.Format = False
.Find.MatchCase = False
.Find.MatchWholeWord = False
.Find.MatchWildcards = False
.Find.MatchSoundsLike = False
.Find.MatchAllWordForms = False
Loop While .Find.Execute = True

The doc is open and I can see the highlighted text of "Purpose:" but
it is followed by a space or two and then some text. I want to
extract the text but have tried several variations of code without
success.

Your help is greatly appreciated.
Nov 13 '05 #1
3 2519
I'm not adept at this but if no one replies. I suggest playing with the
movement methods. moveright 1 word no extend etc.

hope this get you started
ano1optimist <an**********@aol.com> posted in
news:25**************************@posting.google.c om
I've got the code to search through a directory for word documents,
open the doc, search for specific text... but I'm trying to extract
data that immediately follows the selected highlighted text. I can't
figure out the correct syntax to give me the text that follows the
currently selected text. Here is my code:

Set objword = New Word.Application
objword.Documents.Add "filename.doc"
objword.WindowState = wdWindowStateMaximize
objword.Visible = True
With objword.Selection
Do
.Find.Text = "Purpose:"
.Find.Forward = True
.Find.Wrap = wdFindStop
.Find.Format = False
.Find.MatchCase = False
.Find.MatchWholeWord = False
.Find.MatchWildcards = False
.Find.MatchSoundsLike = False
.Find.MatchAllWordForms = False
Loop While .Find.Execute = True

The doc is open and I can see the highlighted text of "Purpose:" but
it is followed by a space or two and then some text. I want to
extract the text but have tried several variations of code without
success.

Your help is greatly appreciated.


--
Phil
Nov 13 '05 #2
an**********@aol.com (ano1optimist) wrote in message news:<25**************************@posting.google. com>...
I've got the code to search through a directory for word documents,
open the doc, search for specific text... but I'm trying to extract
data that immediately follows the selected highlighted text. I can't
figure out the correct syntax to give me the text that follows the
currently selected text. Here is my code:

Set objword = New Word.Application
objword.Documents.Add "filename.doc"
objword.WindowState = wdWindowStateMaximize
objword.Visible = True
With objword.Selection
Do
.Find.Text = "Purpose:"
.Find.Forward = True
.Find.Wrap = wdFindStop
.Find.Format = False
.Find.MatchCase = False
.Find.MatchWholeWord = False
.Find.MatchWildcards = False
.Find.MatchSoundsLike = False
.Find.MatchAllWordForms = False
Loop While .Find.Execute = True

The doc is open and I can see the highlighted text of "Purpose:" but
it is followed by a space or two and then some text. I want to
extract the text but have tried several variations of code without
success.

Your help is greatly appreciated.


Perhaps something like:

..EndKey Unit:=wdLine, Extend:=wdExtend

to include the text to the end of the line along with the found string.

James A. Fortune
Nov 13 '05 #3
Thanks for the posts. I had to use a combination of suggestions in
order to parse 2 fields from the word doc. Here is a sample of my
code:

With objword.Selection
' Do
' find the pf number first
.Find.Text = "PF:"
.Find.Forward = True
.Find.Wrap = wdFindContinue
.Find.Format = False
.Find.MatchCase = False
.Find.MatchWholeWord = False
.Find.MatchWildcards = False
.Find.MatchSoundsLike = False
.Find.MatchAllWordForms = False
.Find.Execute

.EndKey Unit:=wdLine, Extend:=wdExtend
PFNumber = Mid(objword.Selection, 4)

.Move Unit:=wdWord, Count:=1
' then find the purpose of examination
.Find.Text = "Purpose of Examination:"
.Find.Forward = True
.Find.Wrap = wdFindStop
.Find.Format = False
.Find.MatchCase = False
.Find.MatchWholeWord = False
.Find.MatchWildcards = False
.Find.MatchSoundsLike = False
.Find.MatchAllWordForms = False
.Find.Execute

.EndKey Unit:=wdLine, Extend:=wdExtend
Purpose = Mid(objword.Selection, 24)
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cassandra.flowers | last post by:
Hi, I am using VB6 and want to extract text from a string. But ONLY take out words that begin with 't' or 'd'. The mainstring is input by the user into 'txtMain' and then by clicking a command...
9
by: Wang, Jay | last post by:
Hello, all, I would like to enable some text between <SPAN url="http://www.testserver.com/">WORD TO BE DRAGGED </SPAN>. I put some javascript and it will extract http://www.testserver.com/ from...
1
by: mickeydisn | last post by:
Sub: C++ Word automation Extract text hello. I want extact text form a word document using a visual c++ programme. I have see a lot of documentation. and my analysis is that I must use a...
4
by: Barry | last post by:
How can I open a word doc and extract the text as text without any formatting characters?? -- Barry Fitzgerald
2
by: Kevin K | last post by:
Hi, I'm having a problem with extracting text from a Word document using StreamReader. As I'm developing a web application, I do NOT want the server to make calls to Word. I want to simply...
7
by: teo | last post by:
hallo, I need to extract a word and few text that precedes and follows it (about 30 + 30 chars) from a long textual document. Like the description that Google returns when it has found a...
2
by: teo | last post by:
I have a problem (partial). Some days ago I asked for a way to extract a word and few text around it (30 chars on the left and 30 on the right) from a long text. I went good with: ...
17
by: Umesh | last post by:
Can anyone do it? ARMY1987- what say?
0
by: ayyanarj | last post by:
Hi, I have a word document that has attached(ie. embedded ) documents like word, ppt, pdf, etc. I have to extract those embedded documents in the document through code. To extract...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.