Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to let the user choose the file to read

Status
Not open for further replies.

ologist

Technical User
Aug 27, 2003
3
US
Hello,

Instead of making the user type in the path and file name to read the data from, I would like to have a button that will automatically pop up a window that will allow the user to browse for the file. i then want that path and file name to show up in a cell on the spreadsheet.

Thanks for any help!! : )
 
That sounds like a "ComboBox"... doesn't it?
 
Thanks--I figured it out. I needed to use the GetOpenFilename application to pop up a browse box. I think the combo box would only work if I had a list of all the files to choose from in the spreadsheet somewhere.
 
Just in case you're still interested.

Code:
Sub ReturnFileNameToCell()
    Dim Filt As String
    Dim FilterIndex As Integer
    Dim FileName As Variant
    Dim Title As String
'   File filters
    Filt = "Excel Files (*.xls),*.xls," & _
           "Text Files (*.txt),*.txt," & _
           "All Files (*.*),*.*"
'   Default *.*
    FilterIndex = 3
'   Dialog Caption
    Title = "Select a File to Import"
'   File Name
    FileName = Application.GetOpenFilename(FileFilter:=Filt, _
         FilterIndex:=FilterIndex, Title:=Title)
'   Exit on Cancel
    If FileName = False Then
        MsgBox "No file was selected."
        Exit Sub
    End If
'   Return full path and name of the file to a cell
    Range("A1") = "You selected " & FileName
End Sub

I hope this helps!



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top