I have this code for searching a string in text files. It shows me each file name where the string was found. How do I update this to show all the filenames at once?
Code:
Sub PartUsedOn()
Dim theString As String
Dim path As String
Dim StrFile As String
Dim fso As New FileSystemObject '''Add to: Tools/References - Microsoft Scripting Runtime
Dim file As TextStream
Dim line As String
theString = UCase(InputBox("Part Number?"))
path = "C:\Scripts\"
StrFile = Dir(path & "*.dp")
Do While StrFile <> ""
Set file = fso.OpenTextFile(path & StrFile)
Do While Not file.AtEndOfLine
line = file.ReadLine
If InStr(1, line, theString, vbTextCompare) > 0 Then
msgStrFile = StrFile & " - " & line
End If
Loop
file.Close
Set file = Nothing
Set fso = Nothing
StrFile = Dir()
Loop
End Sub