Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
GetOpenFilename type mismatch
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! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
GetOpenFilename type mismatch
I've never encountered this that I can recall, and I use GetOpenFileName a
lot. If you only return one file, it should be an array with one element, but I've never explicitly tried hitting Enter without selecting a file first. You could check TypeName(arrFileNames) for Variant() or just IsArray(arrFileNames) before you loop through the array. - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions http://PeltierTech.com _______ "XLHead" wrote in message ups.com... 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! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
type mismatch | Excel Programming | |||
Type Mismatch: array or user defined type expected | Excel Programming | |||
Type mismatch using rnge as Range with Type 8 Input Box | Excel Programming | |||
Help: Compile error: type mismatch: array or user defined type expected | Excel Programming | |||
Type Mismatch | Excel Programming |