Ok, so I'm not sure if anyone will be able to help here or not but I am looking for code that will allow me to search through the contents of files in a drive or directory for a string.
There is probably a better way to do this, but this is how I do it:
Sub SearchFiles(NamePart As String, FolderPath As String, Files() As String)
Dim objFS
Dim objFolder
Dim File
Dim k As Integer
Set objFS = CreateObject("Scripting.FileSystemObject"
Set objFolder = objFS.GetFolder(FolderPath)
For Each File In objFolder.Files
If InStr(File.Name, NamePart) > 0 Then
k = k + 1
ReDim Preserve Files(k)
Files(k) = File.Name
End If
Next
Set objFolder = Nothing
Set objFS = Nothing
End Sub
Here is a sample Form:
Private Sub Command1_Click()
Dim FileList() As String
Dim k As Integer
Call SearchFiles(TxtInput, txtFolder, FileList())
For k = LBound(FileList()) To UBound(FileList())
TxtOutput = TxtOutput & FileList(k) & vbCrLf
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.