View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ian Digby[_3_] Ian Digby[_3_] is offline
external usenet poster
 
Posts: 15
Default A Macro to search a string in a Word file

Hi Farooq,

The code below will find the first occurrence, then shut down Word. Just
change sText and sDoc to your own ones.

Private Sub CommandButton1_Click()
Dim sText As String, sDoc as String
Dim wordApp As Object

sText = "Find this"
sDoc="C:\Temp\A Document.doc"
Set wordApp = CreateObject("Word.Application")
With wordApp
.Visible = True
.Documents.Open (sDoc)
With .Selection.Find
.Text = sString
.Execute Forward:=True
End With
.Quit
End With
Set wordApp = Nothing
End Sub

--
Work performed in the spirit of service is worship...Baha'i Writings


"Farooq Sheri" wrote:

Greetings,

Please help me with the following: I have an excel sheet with data
pertaining to telcomm switch. I have a command button on the sheet. When I
click the command button it asks me for a string. I then want to open a WORD
file and search for the same string in the Word file. I want the option to
find the next possible occurance of the string within the Word file. At the
end of it all I want to close the Word file.

Thanks in advance for your help.

Farooq Sheri