Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
type mismatch Craig[_24_] Excel Programming 1 August 1st 06 05:35 PM
Type Mismatch: array or user defined type expected ExcelMonkey Excel Programming 4 July 6th 06 03:40 PM
Type mismatch using rnge as Range with Type 8 Input Box STEVE BELL Excel Programming 11 December 3rd 05 05:02 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Type Mismatch Brad Excel Programming 2 May 2nd 05 04:49 PM


All times are GMT +1. The time now is 05:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"