By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,230 Members | 2,471 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,230 IT Pros & Developers. It's quick & easy.

Found Text but Can't Extract from Word Doc

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.