Finding and selecting text in word from excel

A

akh2103

Hello--I have written a simple macro trying to find and select certain
text in a word document (it is part of a larger project). When the
macro is finished running, I would like word to have the first instance
of the text selected. However, the following code is not doing the job.
I am sure I am missing something simple. Can anyone help?
-Abe

Sub find()

Set wdapp = GetObject(, "Word.Application")
Set wddoc = wdapp.ActiveDocument

With wddoc.Content.find
.Text = "Q1"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchAllWordForms = False
.Execute (findtext = "Q1")
End With

End Sub
 
A

akh2103

This one is actually embarrassingly simple. I am missing the statement
Selection.Find.Execute at the end of the find code. I guess the find
property needs an additional step to be completed. The working code
goes:


Set wdapp = GetObject(, "Word.Application")
 

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