Is there a Dialog or simple userform to allow a user to choose a filename (not a directory!)?


Posted by Chris on January 03, 2002 9:29 AM

Experts,

Is there a Dialog or simple userform to allow a user to choose a filename (not a directory!)?

This message is similar to #1873 I think. I just need to know if theres an API function for browsing to an actual file and then getting its path/filename so I can use it in VBA.

Any help is greatly appreciated.

Thanks,
Chris

Posted by Fulvia on January 03, 2002 5:46 PM

Here's one way.
It displays the Open File dialog box, opens the file selected, stores the file name in a variable, then closes the file :-

Sub Select_File_Name()
Dim FileName As String, response As Boolean
response = Application.Dialogs(xlDialogFindFile).Show
If response = 0 Then GoTo nxt ActiveWorkbook.FullName
ActiveWorkbook.Close saveChanges:=False
MsgBox FileName
nxt:
End Sub

Posted by Fulvia on January 03, 2002 5:48 PM

Correction ...


Should be :-

Sub Select_File_Name()
Dim FileName As String, response As Boolean
response = Application.Dialogs(xlDialogFindFile).Show
If response = 0 Then GoTo nxt
FileName = ActiveWorkbook.FullName
ActiveWorkbook.Close saveChanges:=False
MsgBox FileName
nxt:
End Sub




Posted by Chris on January 04, 2002 6:37 AM

Re: Correction ...

Fulvia -

Thanks! I think I can work with this and get it to do what I need.


--Chris