Searching a Word Document from Excel

V

VFXer

I am trying to write a Macro to be used in Excel that will search a number of
Word documents for certain words or phrases. This needs to work similar to
the way you can do it when you use the Search for Files or Folder and fill in
the "A Word or Phrase in the file" box. Does anyone know of any examples for
this.

Thanks
 
H

Helmut Weber

Hi,

something along these lines:

Sub Test455()
Dim sPth As String
Dim sNam As String
Dim oWrd As Object
sPth = "c:\test\word1\"
Set oWrd = CreateObject("Word.Application")
' Set oWrd = GetObject(, "Word.Application")
oWrd.Visible = True
sNam = Dir(sPth & "*.doc")
While sNam <> ""
oWrd.documents.Open sPth & sNam
Dim rDcm As Object
Set rDcm = oWrd.activedocument.Range
With rDcm.Find
.Text = "fox"
While .Execute
rDcm.Select
Stop
' what now ?
Wend
End With
oWrd.activedocument.Close
sNam = Dir
Wend
oWrd.Quit
Set oWrd = Nothing
End Sub

Which uses late binding,
as early binding doesn't work here and now,
due to a preconfigured chinese PC.

See:
http://word.mvps.org/FAQs/InterDev/EarlyvsLateBinding.htm

See:
http://word.mvps.org/faqs/interdev/ControlWordFromXL.htm

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
V

VFXer

Thanks. I will try that tomorrow. I'm sure with a little modification I can
get it to works for my needs..

Thanks for your help.
 

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