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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a combobox list of images in Word VBA Form

Status
Not open for further replies.

mdav2

Programmer
Aug 22, 2000
363
GB
I am trying to create a list of image files jpg and gif from 1 directory on the HD. I have the code to return one file using FOUNDFILE. The FILENAME property can be set to "*.jpg" to find jpgs and "*.gif" to find gifs. However I cant combine the two.

Is there another way to do this?

Code:
-----
' locate the files
Set fs = Application.FileSearch
With fs
.LookIn = "C:\work"
.FileName = "*.jpg"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 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
 
I found the answer.
Use a semi-colon to separate the entries.

EG:

' locate the files
Set fs = Application.FileSearch
With fs
.LookIn = "C:\work"
.FileName = "*.jpg;*.gif;*.bmp"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top