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
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