Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default A Macro to search a string in a Word file

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default A Macro to search a string in a Word file

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.

"Ian Digby" wrote:

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

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 to search a word in a excel file which appears twice Jegadeesan P r Excel Discussion (Misc queries) 0 October 26th 06 11:26 AM
search for a word in csv file cgkuhle Excel Discussion (Misc queries) 1 May 15th 06 01:53 PM
WORD-DELIMITED string vba macro for excel/word jackal2k6 Excel Programming 3 December 23rd 05 04:32 PM
search a string withing a string : find / search hangs itarnak[_9_] Excel Programming 4 October 24th 05 03:19 PM
Search a text file for a string crazybass2 Excel Programming 2 June 21st 05 12:53 AM


All times are GMT +1. The time now is 06:52 AM.

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"