Hi Everyone,
Quite new to VBA and would really appreciate some help please ?
I have a macro in a workbook that when ran, scans a drive that the user selects and looks for all files that contain the keyword provided. Is there anyway to:
1. Get it to scan also the subfolders within the folder selected by the user?
2. Allow for multiple keywords to be searched at one time ?
This is the code:
Have been at this for a few days now, just can't seem to change it to work.
Many many thanks in advance for any guidance here please.
Quite new to VBA and would really appreciate some help please ?
I have a macro in a workbook that when ran, scans a drive that the user selects and looks for all files that contain the keyword provided. Is there anyway to:
1. Get it to scan also the subfolders within the folder selected by the user?
2. Allow for multiple keywords to be searched at one time ?
This is the code:
VBA Code:
Sub ListFilesContainingString()
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = strPath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
getfolder = sItem
Set fldr = Nothing
wrd = InputBox("Word:", "Insert search word")
If wrd = "" Then
MsgBox "???"
Exit Sub
End If
strfile = Dir(getfolder & "\*" & wrd & "*")
fc = 0
Do While Len(strfile) > 0
fc = fc + 1
Cells(fc, 1).Value = strfile
strfile = Dir
Loop
End Sub
Have been at this for a few days now, just can't seem to change it to work.
Many many thanks in advance for any guidance here please.