View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Justin Hebert Justin Hebert is offline
external usenet poster
 
Posts: 2
Default Populate Listbox with File Name Only

Thanks for the replies. The Subs Worked great, yet I couldn't feed them
into my code. Thanks for the help



Sub SummarySheetSearchListBox()

' Dimension variables.
Dim myarray()
Dim FS As Object
Dim i As Integer
Dim NextFile As String

' Declare filesearch object.
Set FS = Application.FileSearch

' Set folder to search.
FS.LookIn = "C:\Summary Sheets\"

' Set file name to search for.
FS.Filename = ("*.xls")


' Execute the file search, and check to see if the file(s) are present.
If FS.Execute 0 Then

' Redimension the array to the number of files found.
ReDim myarray(FS.FoundFiles.Count)

' Loop through all found file names and fill the array.
For i = 1 To FS.FoundFiles.Count
myarray(i) = FS.FoundFiles(i)
Next i
Else
' Display message if no files were found.
MsgBox "No files were found"
End If

' Loop through the array and fill the list box on the UserForm.
For i = 1 To FS.FoundFiles.Count
SummarySheet.ListBox1.AddItem myarray(i)
Next i

' Display the UserForm.
SummarySheet.Show

End Sub

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!