View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Patrick Kirk Patrick Kirk is offline
external usenet poster
 
Posts: 19
Default 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