Error I can't get rid of with open dialog box

G

Guest

I have the code below that will allow multiple selections of files from a
dialog box. When I don't select anything and click cancel it gives me an
error. I tried to disable warnings and that didn't work. I also checked if
v was null or empty and that got rid of the error when I didn't select
anything. But when I selected files it would give me an error.

I'm assuming that it has to do with v being a variant. I'm not sure how to
deal with this and catch the errors so they don't show up.


Dim v as Variant

v = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls),*.xls",
FilterIndex:=1, Title:="Select File(s)", MultiSelect:=True)

If Not IsEmpty(rng) Then rng = rng.Offset(1, 0)
rng.Resize(UBound(v) - LBound(v) + 1, 1).Value = Application.Transpose(v)
 
B

Bill Manville

Dim v as Variant

v = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls),*.xls",
FilterIndex:=1, Title:="Select File(s)", MultiSelect:=True)
If TypeName(v)<>"Boolean" Then ' GetOpenFilename returns False on cancel
If Not IsEmpty(rng) Then rng = rng.Offset(1, 0)
rng.Resize(UBound(v) - LBound(v) + 1, 1).Value = Application.Transpose(v)
End If
Pokdbz said:
Dim v as Variant

v = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls),*.xls",
FilterIndex:=1, Title:="Select File(s)", MultiSelect:=True)

If Not IsEmpty(rng) Then rng = rng.Offset(1, 0)
rng.Resize(UBound(v) - LBound(v) + 1, 1).Value = Application.Transpose(v)

Bill Manville
MVP - Microsoft Excel, Oxford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top