"Find" failing in Word VBA - is it Word or me?

I

Ian B

Hi all
I have a word macro which has a main form with various buttons, one of which
calls a vb executable.
One of the functions in the vb exe gets a handle on word, opens an rtf file,
searches through the doco looking for the letter "B" with the Option "Select
whole words only", and builds an array for subsequent processing
This works fine if the calling macro is closed each time. (Condition A) -
But if another button is activated on the main form which involves a large
amount of reformatting of very complex documents, and the calling macro is
not closed, but a button is then activated to launch the vb exe the "Select
whole words only" find option is totally ignored(Condition B).
see snips below
(Condition A) puts ReturnedDocsList & X into the array
(Condition B) puts T & 0 into the array

My work around is to check that the "B" is also in left hand column, where
it always will be
I need to tidy the "Withs" a bit but thats cosmetic What is preventing the
"Select whole words only" from working when the calling macro is not
unloaded?

Any ideas appreciated.

Ian B

Here is a snip of the document.
C
BorrowerAddress
T
0


B
ReturnedDocsList
X
0







Here is a snip of the code:
Set oWord = GetObject(, "Word.Application")
Set oDoc = oWord.Documents.Open(sMainTemplate, False, True)
oWord.Selection.HomeKey Unit:=wdStory
With oWord
.Selection.Find.ClearFormatting
.Selection.Find.Replacement.ClearFormatting
End With
With oWord.Selection.Find
.MatchWholeWord = True
.Text = "B"
.Forward = True
End With
oWord.Selection.Find.Execute
If oWord.Selection.Find.Found = False Then
GoTo Fin
End If
~~~

For those of you who read this far it demonstrates perfectly a point Jezebel
made when replying to another recent post of mine re mixing VBA and VB.
Do one or the other - its very difficult to debug when word calls a Vb exe
which then runs word commands
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top