Open File box in VB


Posted by Chris on October 02, 2001 8:29 AM

I know I've seen this before on here, but I can't find it. I want a macro to open a file, but I want it to let me chooose the file. I can't remember the object for it.

Posted by Dank on October 02, 2001 9:40 AM

How about this?

Sub OpenAFile()
Dim sFilename As String

sFilename = Application.GetOpenFilename("Excel files,*.xls", , "Select a file")

If sFilename = "False" Then Exit Sub

Workbooks.Open sFilename

End Sub

regards,
Dan.

Posted by Ryan on October 02, 2001 9:42 AM

This should work. I create a sub and call this from either a toolbar or button.


sFile = Application.GetOpenFilename( _
FileFilter:="Text Files (*.xls), *.xls", FilterIndex:=1, _
Title:="Open Workbook")



Posted by Chris on October 02, 2001 9:56 AM

Exactly what I was looking for. Thanks