Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Searching a Word Document from Excel

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Searching a Word Document from Excel

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/E...ateBinding.htm

See:
http://word.mvps.org/faqs/interdev/C...WordFromXL.htm

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Searching a Word Document from Excel

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.

"Helmut Weber" wrote:

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/E...ateBinding.htm

See:
http://word.mvps.org/faqs/interdev/C...WordFromXL.htm

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I convert an Excel document to a Word Document has3801 Setting up and Configuration of Excel 1 June 11th 08 11:16 PM
change excel document into word document mrsb Excel Discussion (Misc queries) 6 August 28th 07 12:58 PM
Searching within an excel document Willsecur Excel Worksheet Functions 5 June 29th 07 10:53 AM
convert excel document to word document (not a picture) frendabrenda1 Excel Discussion (Misc queries) 2 October 6th 06 03:55 PM
How to change a excel document into a word document? wannaknow Excel Discussion (Misc queries) 1 July 27th 05 09:37 PM


All times are GMT +1. The time now is 07:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"