Search and open word file based on excel cell value

alattiaa

New Member
Joined
Aug 3, 2016
Messages
2
Please help in the below code, trying to find a way, ( formula or code) to search all parent folder Z: \ All Files contains and its sub-folders which had several word files. I need a code so that when you press the Search button the device to searching for the name in cell A2, and search for the file of the same name ( partially if applicable) on the main folder Z: \ all Files and all its sub-folders, and to show search result and, if possible to open the file.


Sub File_Search()
'
Dim o_Word
Dim o_Doc
Set o_Word = CreateObject("Word.Application")
'==========================================================================
Path = Range("H2")
File_Name = Range("A2")
'==========================================================================
With Application.FileSearch
.NewSearch
.LookIn = Path
.SearchSubFolders = True
.Filename = File_Name
.MatchTextExactly = True
.FileType = msoFileTypeWordDocuments
If .Execute > 0 Then
For x = 1 To .FoundFiles.Count
Set o_Doc = o_Word.Documents.Open(.FoundFiles(x))
o_Word.Visible = True


Next
End If
End With
'==========================================================================
'
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top