![]() |
Search Directories/SubDirectories UserForm
Would anyone know how to create a userform that searches all subdirectories
for a particular name (ex: Any file with R0012 in it's name) and list the findings within the form itself? Another example, if I used the search function on Windows (start, search, find...), the results should be within the userform with a scroll bar to show all. Any help anyone can give will be greatly appreciated. -- PK |
Search Directories/SubDirectories UserForm
Hi Patrick
The code below is pretty much the code stright from the excel VBA help file. To test it create a userform with a listbox and a button and paste the code below to userform module. Option Explicit Dim Fs As Object Dim i As Integer Private Sub CommandButton1_Click() Set Fs = Application.FileSearch With Fs 'Change below to give the name of the Directory you want to search .LookIn = "C:\" .SearchSubFolders = True .Filename = "*R0012*" If .Execute() 0 Then For i = 1 To .FoundFiles.Count ListBox1.AddItem (.FoundFiles(i)) Next i Else MsgBox "There were no files found." End If End With End Sub Hope this helps Steve |
Search Directories/SubDirectories UserForm
Incidental, thank you. It works great!
-- PK "Incidental" wrote: Hi Patrick The code below is pretty much the code stright from the excel VBA help file. To test it create a userform with a listbox and a button and paste the code below to userform module. Option Explicit Dim Fs As Object Dim i As Integer Private Sub CommandButton1_Click() Set Fs = Application.FileSearch With Fs 'Change below to give the name of the Directory you want to search .LookIn = "C:\" .SearchSubFolders = True .Filename = "*R0012*" If .Execute() 0 Then For i = 1 To .FoundFiles.Count ListBox1.AddItem (.FoundFiles(i)) Next i Else MsgBox "There were no files found." End If End With End Sub Hope this helps Steve |
All times are GMT +1. The time now is 11:25 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com