Hello,
You can try this:
Private Keyword As String
Private ReturnedFilePath As String
Private KeywordLocationInFile As Integer
Sub FindKeyword()
Dim FileSystem As Object
Dim FolderToSearchIn As String
Keyword = "Hello World"
FolderToSearchIn = "C:\"
Set FileSystem = CreateObject("Scripting.FileSystemObject")
LoopThroughFolder (FileSystem.GetFolder(FolderToSearchIn))
If Not ReturnedFilePath = "" Then
MsgBox (ReturnedFilePath)
MsgBox (KeywordLocationInFile)
End If
End Sub
Sub LoopThroughFolder(Folder)
Dim SubFolder
Dim File
For Each SubFolder In Folder.SubFolders
LoopThroughFolder SubFolder
Next
For Each File In Folder.Files
Dim strFilename As String
Dim strFileContent As String
Dim iFile As Integer
strFilename = File
iFile = FreeFile
Open strFilename For Input As #iFile
strFileContent = Input(LOF(iFile), iFile)
Close #iFile
If InStr(strFileContent, Keyword) > 0 Then
ReturnedFilePath = File
KeywordLocationInFile = InStr(strFileContent, Keyword)
Exit Sub
End If
Next
End Sub
I hope it helps.