473,563 Members | 2,556 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Applicatio n
objword.Documen ts.Add "filename.d oc"
objword.WindowS tate = wdWindowStateMa ximize
objword.Visible = True
With objword.Selecti on
Do
.Find.Text = "Purpose:"
.Find.Forward = True
.Find.Wrap = wdFindStop
.Find.Format = False
.Find.MatchCase = False
.Find.MatchWhol eWord = False
.Find.MatchWild cards = False
.Find.MatchSoun dsLike = False
.Find.MatchAllW ordForms = 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 2535
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**********@a ol.com> posted in
news:25******** *************** ***@posting.goo gle.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.Applicatio n
objword.Documen ts.Add "filename.d oc"
objword.WindowS tate = wdWindowStateMa ximize
objword.Visible = True
With objword.Selecti on
Do
.Find.Text = "Purpose:"
.Find.Forward = True
.Find.Wrap = wdFindStop
.Find.Format = False
.Find.MatchCase = False
.Find.MatchWhol eWord = False
.Find.MatchWild cards = False
.Find.MatchSoun dsLike = False
.Find.MatchAllW ordForms = 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**********@ao l.com (ano1optimist) wrote in message news:<25******* *************** ****@posting.go ogle.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.Applicatio n
objword.Documen ts.Add "filename.d oc"
objword.WindowS tate = wdWindowStateMa ximize
objword.Visible = True
With objword.Selecti on
Do
.Find.Text = "Purpose:"
.Find.Forward = True
.Find.Wrap = wdFindStop
.Find.Format = False
.Find.MatchCase = False
.Find.MatchWhol eWord = False
.Find.MatchWild cards = False
.Find.MatchSoun dsLike = False
.Find.MatchAllW ordForms = 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:=wdExten d

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.Selecti on
' Do
' find the pf number first
.Find.Text = "PF:"
.Find.Forward = True
.Find.Wrap = wdFindContinue
.Find.Format = False
.Find.MatchCase = False
.Find.MatchWhol eWord = False
.Find.MatchWild cards = False
.Find.MatchSoun dsLike = False
.Find.MatchAllW ordForms = False
.Find.Execute

.EndKey Unit:=wdLine, Extend:=wdExten d
PFNumber = Mid(objword.Sel ection, 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.MatchWhol eWord = False
.Find.MatchWild cards = False
.Find.MatchSoun dsLike = False
.Find.MatchAllW ordForms = False
.Find.Execute

.EndKey Unit:=wdLine, Extend:=wdExten d
Purpose = Mid(objword.Sel ection, 24)
Nov 13 '05 #4

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

Similar topics

1
10458
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 button, all the words that begin with 't' or 'd' will be extracted and appear in a second text box, txtExtract. So, i know that I have to search...
9
6795
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 the the span element when I select the whole text in the SPAN and drag it. However, I want to drag it without have to select the words between the...
1
12068
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 "word automation". I have foud a lot of exemple to use it but I need your precious help to
4
2113
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
2491
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 open the Word document via StreamReader and extract the text. Here's the problem, the users insist on leaving the "Track Changes" features on. ...
7
2874
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 given word. In example from:
2
1860
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: ..{1,30}?myWord.{1,30}
17
2880
by: Umesh | last post by:
Can anyone do it? ARMY1987- what say?
0
1264
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 embedded word document. I used the following code.
0
7579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7877
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7631
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7943
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6238
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5479
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5204
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2077
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.