X
XLHead
Hi,
I am new to this group (and programming).
I have a userform with a listbox that is to be populated with user
selected filenames.
When the user clicks a button on the worksheet I have the the userform
open, the Activate event calls a macro with GetOpenFilenames
(Multiselect = True).
I have a variable called arrFileNames as Variant for the array of file
names.
When I try to add the names to the ListBox I get runtime error 13 -
Type mismatch... sometimes. If the Open dialog box opens and I just
click open without selecting a file it will sometimes put the default
selected file name in the ListBox.
Here is the code that is called from the UserForm_Activate() event:
Private Sub cmdGet_Click()
' Get list of files to import and put in list box.
Dim i As Integer
Dim arrFileNames As Variant
arrFileNames = Application.GetOpenFilename(, 1, _
"Select One Or More Files To Open", , True)
If TypeName(arrFileNames) = "Boolean" Then Exit Sub 'cancel
pressed
For i = LBound(arrFileNames) To UBound(arrFileNames)
lbxFiles.AddItem funcRemovePath(CStr(arrFileNames(i)))
lbxFiles.List(lbxFiles.ListCount - 1, 1) = CStr(arrFileNames(i))
Next i
End Sub
I am getting the error at the LBound(arrFileNames) line.
Am I doing something wrong or is this just some strange bug? It's
driving me nuts!
I am new to this group (and programming).
I have a userform with a listbox that is to be populated with user
selected filenames.
When the user clicks a button on the worksheet I have the the userform
open, the Activate event calls a macro with GetOpenFilenames
(Multiselect = True).
I have a variable called arrFileNames as Variant for the array of file
names.
When I try to add the names to the ListBox I get runtime error 13 -
Type mismatch... sometimes. If the Open dialog box opens and I just
click open without selecting a file it will sometimes put the default
selected file name in the ListBox.
Here is the code that is called from the UserForm_Activate() event:
Private Sub cmdGet_Click()
' Get list of files to import and put in list box.
Dim i As Integer
Dim arrFileNames As Variant
arrFileNames = Application.GetOpenFilename(, 1, _
"Select One Or More Files To Open", , True)
If TypeName(arrFileNames) = "Boolean" Then Exit Sub 'cancel
pressed
For i = LBound(arrFileNames) To UBound(arrFileNames)
lbxFiles.AddItem funcRemovePath(CStr(arrFileNames(i)))
lbxFiles.List(lbxFiles.ListCount - 1, 1) = CStr(arrFileNames(i))
Next i
End Sub
I am getting the error at the LBound(arrFileNames) line.
Am I doing something wrong or is this just some strange bug? It's
driving me nuts!