Using xlDialogFindFile to get filename and path.

H

Henry

I'm trying to get a filename and path from users using xlDialogFindFile. I
don't want the selected file to be opened.

1) How do I get xlDialogFindFile to open showing .doc and .txt as the
default type files?
2) How do I get the selected filename and path returned from
xlDialogFindFile without opening the file?
3) How do I stop xlDialogFindFile causing an error when a .doc or .txt file
is chosen?

If I'm trying to use the wrong dialog, can you please point me to what I
should use instead.
I realise that I could design my own dialog, but why re-invent the wheel?

I've not got very far with the code, but here it is.

Private Sub BrowseButton1-Click()
Dim MyFile
MyFile = Application.Dialogs(xlDialogFindFile).Show <--------
'<--------- Returns error if non XL file selected, opens file and returns
"True" if XL file selected
MsgBox MyFile
End Sub
 
P

Per Jessen

Hi

You should use "GetOpenFileName".

MyFile = Application.GetOpenFilename
If fileToOpen <> False Then
MsgBox MyFile
End If

Regards,
Per
 
H

Henry

Thanks very much Per,
That works 100%!

Henry

Per said:
Hi

You should use "GetOpenFileName".

MyFile = Application.GetOpenFilename
If fileToOpen <> False Then
MsgBox MyFile
End If

Regards,
Per
 

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