Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing files in a ComboBox

Status
Not open for further replies.

JaneB19

Technical User
Jun 27, 2002
110
GB
Hi,

I'm having a bit of trouble with this and I'm hoping that somebody can help me!? I'm wanting to show the names of avaliable files in a combo or list box. At the moment I have the following coding

Private Sub UploadButton_Click()
With Application.FileSearch
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With

With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents\ScoreCards\Trial"
.SearchSubFolders = True
.FileType = msoFileTypeExcelWorkbooks
End With

End Sub

This shows me the number of files in a message box, and then proceds to show me the path to those files. What I would like to happen is for those files to be shown in a combo or list box instead. Is this possible? And if so, how can I manipulate the coding I have at the moment, to do this?

Thanks
Jane

[PC2]
 
Hi Jane,
You nearly had it yourself anyway, if you haven't already figured it out, try this ....


you will need to add a combo box of course!

Private Sub UploadButton_Click()

With Application.FileSearch
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
ComboBox1.AddItem .FoundFiles(i) ' #change this line#
Next i
Else
MsgBox "There were no files found."
End If
End With

With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents\ScoreCards\Trial"
.SearchSubFolders = True
.FileType = msoFileTypeExcelWorkbooks
End With

End Sub

Mike [pipe]

 
Just a quick note:

You might want to add the following line to the code to ensure that the combobox list doesn't contain any duplicate (or more) values if the "UploadButton" is clicked more than once:

Code:
Private Sub UploadButton_Click()

With Application.FileSearch
    If .Execute() > 0 Then
        MsgBox "There were " & .FoundFiles.Count & " file(s) found."
        For i = 1 To .FoundFiles.Count
Code:
ComboBox1.Clear
Code:
            ComboBox1.AddItem .FoundFiles(i) ' #change this line#
Code:
        Next i
    Else
        MsgBox "There were no files found."
    End If
End With

With Application.FileSearch
    .NewSearch
    .LookIn = "C:\My Documents\ScoreCards\Trial"
    .SearchSubFolders = True
    .FileType = msoFileTypeExcelWorkbooks
End With
        
End Sub

Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top