Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Search Directories/SubDirectories and Display in ListBox or MsgBox

I have modified the code below from a reply to a question in 2007 from
Patrick Kirk. I am using MS Office Excel 2003.

For my use I would prefer the results within 2 possible scenarios;

1) a ListBox so that I may choose just see or select a file that was found
and proceed to work with it, such as open an XLS, if the file is an XLS file.
2) a MsgBox, but each file found must be displayed on separate lines within
the MsgBox

The difference for me too is that this IS NOT for a user form but rather a
macro that can be assigned to a button.

Suggestions?


Sub findFile()
Dim showThis As String
Dim i As Integer

Set Fs = Application.FileSearch
With Fs
'Change below to give the name of the Directory you want to search
.LookIn = "C:\Fun Stuff\Excel\"
.SearchSubFolders = True
.Filename = "msgbox"
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
showThis = showThis & " " & .FoundFiles(i)
'ListBox1.AddItem (.FoundFiles(i))
Next i
MsgBox .FoundFiles.Count & showThis
Else
MsgBox "No files found."
End If
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Search Directories/SubDirectories and Display in ListBox or MsgBox

I believe that your listbox would have to be on a userform, or you would have
to use a sheet form control or data validation list (it really all depends on
how this will be used, and I don't have enough info to suggest which might be
most appropriate).

If you just need to view the list but not select one, then msgbox would work
(although it may have a max string length, I've never checked). To get them
listed on individual lines, I use chr(13) out of habit, but I suspect you
could also use vbcrlf

showThis = showThis & chr(13) & .FoundFiles(i)

HTH,
Keith

"GEdwards" wrote:

I have modified the code below from a reply to a question in 2007 from
Patrick Kirk. I am using MS Office Excel 2003.

For my use I would prefer the results within 2 possible scenarios;

1) a ListBox so that I may choose just see or select a file that was found
and proceed to work with it, such as open an XLS, if the file is an XLS file.
2) a MsgBox, but each file found must be displayed on separate lines within
the MsgBox

The difference for me too is that this IS NOT for a user form but rather a
macro that can be assigned to a button.

Suggestions?


Sub findFile()
Dim showThis As String
Dim i As Integer

Set Fs = Application.FileSearch
With Fs
'Change below to give the name of the Directory you want to search
.LookIn = "C:\Fun Stuff\Excel\"
.SearchSubFolders = True
.Filename = "msgbox"
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
showThis = showThis & " " & .FoundFiles(i)
'ListBox1.AddItem (.FoundFiles(i))
Next i
MsgBox .FoundFiles.Count & showThis
Else
MsgBox "No files found."
End If
End With
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Search Directories/SubDirectories and Display in ListBox or Ms

Thanks Keith, works great.

I tested the MsgBox and there is a restriction of 22 lines of text allowed.
I guess I now need to find a scrollable MsgBox, and I would still like the
idea of having a ListBox I could pick from.


"ker_01" wrote:

I believe that your listbox would have to be on a userform, or you would have
to use a sheet form control or data validation list (it really all depends on
how this will be used, and I don't have enough info to suggest which might be
most appropriate).

If you just need to view the list but not select one, then msgbox would work
(although it may have a max string length, I've never checked). To get them
listed on individual lines, I use chr(13) out of habit, but I suspect you
could also use vbcrlf

showThis = showThis & chr(13) & .FoundFiles(i)

HTH,
Keith

"GEdwards" wrote:

I have modified the code below from a reply to a question in 2007 from
Patrick Kirk. I am using MS Office Excel 2003.

For my use I would prefer the results within 2 possible scenarios;

1) a ListBox so that I may choose just see or select a file that was found
and proceed to work with it, such as open an XLS, if the file is an XLS file.
2) a MsgBox, but each file found must be displayed on separate lines within
the MsgBox

The difference for me too is that this IS NOT for a user form but rather a
macro that can be assigned to a button.

Suggestions?


Sub findFile()
Dim showThis As String
Dim i As Integer

Set Fs = Application.FileSearch
With Fs
'Change below to give the name of the Directory you want to search
.LookIn = "C:\Fun Stuff\Excel\"
.SearchSubFolders = True
.Filename = "msgbox"
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
showThis = showThis & " " & .FoundFiles(i)
'ListBox1.AddItem (.FoundFiles(i))
Next i
MsgBox .FoundFiles.Count & showThis
Else
MsgBox "No files found."
End If
End With
End Sub

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
List Directories and Subdirectories Steven Excel Programming 2 April 22nd 08 02:11 AM
search column and display results in msgbox mike Excel Programming 1 January 23rd 08 03:18 AM
Search Directories/SubDirectories UserForm Patrick Kirk Excel Programming 2 December 23rd 07 02:25 PM
Search all directories for .mdb files Sue Excel Programming 0 July 3rd 07 06:58 PM
VBA code to search and display results in multicolumn listbox [email protected] Excel Programming 6 February 7th 07 01:32 AM


All times are GMT +1. The time now is 08:09 AM.

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"