473,231 Members | 1,572 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,231 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 2512
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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.