View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default GetOpenFileName - no array?

Chip,

Thanks for the suggestion, but it didn't seem to be a problem with not
getting an array when I wasn't supposed to get one. If you're interested I
left more details in my response to Jim. I suppose it was just one of those
things.

By the way, thanks for your suggestion about using named parameters, that
does make it simpler.

"Chip Pearson" wrote:

The following works fine for me in Excel97 through Excel2007.

Sub AAA()
Dim FNames As Variant
Dim N As Long
FNames = Application.GetOpenFilename(filefilter:="Excel Files
(*.xls),*.xls", MultiSelect:=True)
If IsArray(FNames) = True Then
For N = LBound(FNames) To UBound(FNames)
Debug.Print FNames(N)
Next N
Else
Debug.Print "No file selected"
End If
End Sub


x=application.getopenfilename(,,,,true)

You'll find life much simpler if you use named parameters rather than
positional parameters. It makes things MUCH easier to debug.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting LLC
www.cpearson.com
(email on the web site)


"Art" wrote in message
...
A very weird problem...

I've got a few fairly busy workbooks, lots of sheets, lots of code. I
added
the following code:

sub temp
dim x as variant
x=application.getopenfilename(,,,,true)
stop
end sub

When I go into immediate mode, x has a single value, one of the files
selected. If I try to look at x(1) I get an error as x does not seem to
be
an array.

I spent over an hour trying the following:
- got rid of all of the code, except for my temp sub (still failed)
- got rid of all names in the workbook (still failed)
- got rid of all but one sheet (aha!)
- etc.

Eventually I found that if I deleted one sheet in particular, the code
returned an array. Then I re-loaded, left the sheet in, but deleted all
rows
and columns. It worked. I then moved, just moved, another sheet -- it
failed. I moved that other sheet around, and eventually it succeeded and
returned an array.

Can anyone give me any clues as to what's going on?
I'm running Excel 2003(11.8134.8132) SP2