Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

A Macro to search a string in a Word file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Farooq Sheri - 26 Jan 2006 07:59 GMT
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
Ian Digby - 26 Jan 2006 14:27 GMT
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

Signature

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

> Greetings,
>
[quoted text clipped - 8 lines]
>
> Farooq Sheri
Farooq Sheri - 27 Jan 2006 04:53 GMT
Hi Ian,

Thanks for your help. The word document opens but it also closes in a blink
of an eye. Perhaps if we can have a sequence built in where the user
interaction is required to find the next value in the word document and to
finally close the word document (I do not know if it is possible or not but
perhaps after once the Word doc opens, a macro within should Word take over.
After the user has finished finding the required string the word macro should
close and the excel macro should then take over; just a thought).

Thanks again.

> Hi Farooq,
>
[quoted text clipped - 32 lines]
> >
> > Farooq Sheri
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.