I want to read a text file into Excel with VBA. This all works fine with some code I found, the only problem is that the text file I want to open should either be written in the code, or in a textbox but than I have to type the complete location (C:\MyDocuments....) what I would like to have is a browser, similar to the one from Windows on "Ctrl O", which opens when I push a button so I can browse for the file on my hard disk and select the file I want to read into Excel.

Does anybody know if this could be made in VBA, and if it is possible how


Re: Browse hard disk with VBA

Andy Pope


You can use the GetOpenFilename method in Excel to browse for a particular file.
This is straight out of the help file.

fileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
MsgBox "Open " & fileToOpen
End If