Option
Explicit
Private
Sub
ListBox1_Change()
If
ListBox1.ListIndex < 0
Then
Exit
Sub
Call
MsgBox(ListBox1.List(ListBox1.ListIndex, 1))
End
Sub
Private
Sub
UserForm_Initialize()
With
ListBox1
.ColumnCount = 1
.ColumnHeads =
False
.ListStyle = fmListStyleOption
.MultiSelect = fmMultiSelectMulti
End
With
Call
FillListBox(ListBox1, "X:\Images\")
End
Sub
Private
Sub
FillListBox(ListBox
As
MSForms.ListBox,
ByVal
ImagePath
As
String
)
If
Right$(ImagePath, 1) <> "\" _
Then
ImagePath = ImagePath & "\"
Call
ListBox.Clear
Dim
strFile
As
String
Dim
strFileExtension
As
String
strFile = Dir$(ImagePath)
Do
Until
strFile =
""
If
InStrRev(strFile,
"."
) > 0
Then
strFileExtension = Right$(strFile, Len(strFile) - InStrRev(strFile,
"."
))
Else
strFileExtension =
""
End
If
Select
Case
LCase$(strFileExtension)
Case
"bmp"
,
"jpg"
,
"png"
Call
ListBox.AddItem(strFile)
ListBox.List(ListBox.ListCount - 1, 1) = ImagePath & strFile
Case
Else
End
Select
strFile = Dir$()
Loop
End
Sub