Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting names of files in subdirectories David Excel Programming 2 December 5th 07 07:03 PM
All Subdirectories Jim Thomlinson[_4_] Excel Programming 10 July 3rd 07 09:50 PM
Search all directories for .mdb files Sue Excel Programming 0 July 3rd 07 06:58 PM
Search text in multiple files in multiple directories Andrew Excel Programming 4 August 1st 06 03:43 AM
Subdirectories Skip[_4_] Excel Programming 4 August 31st 04 05:59 PM


All times are GMT +1. The time now is 05:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"