View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default GetOpenFilename With MultiSelect Intermittently Returns String

Can't say I ever have that using:
If oSelection < False Then

But with your code, if the return is a string then the code would exit on:
If Not IsArray(oSelection) Then Exit Sub
so how can your code ever error on the For Each line ?

NickHK

"Lazzaroni" wrote in message
...
I am finding that GetOpenFilename does not work consistently with

MultiSelect
set to True. The documentation on GetOpenFilename says that when

MultiSelect
is set to True, it will always return an array unless the cancel button is
clicked, in which case it returns False. Nevertheless, half the time that
multiple files are selected it returns a Variant/String containing only

the
first of the filenames that was selected.

Dim oSelection, oFileName As Variant
oSelection = Application.GetOpenFilename(MultiSelect:=True)
If Not IsArray(oSelection) Then Exit Sub
For Each oFileName In oSelection
MsgBox oFileName
Next

If I step through the code watching the Locals window I can see that after
the selection is made, GetOpenFilename intermittently returns oSelection

as
Variant/Variant( ), in which case the code works correctly. Sometimes,
however, it returns oSelection as Variant/String, in which case the code
fails at "For Each oFileName In oSelection" and the code returns error

"Type
mismatch."

I am not able to replicate this problem and of the few mentions I found of
this error on the internet, nobody seems to have found a solution or

source
of the error.

Any help would be greatly appreciated. Thank you.