File Open Dialog Box

P

Papa Waigo

I am using the macro below to retreives the path and filename of a file
that I select from the File Open dialog box

How can I tweak this macro so that the dialog box always opens in the
C:\Employee Performance\ directory?

Any help would be much appreciatted


Sub GetFileName()
Dim sFileName As String

sFileName = Application.GetOpenFilename
If sFileName = "False" Then Exit Sub
ThisWorkbook.Activate
Range("a1").Value = sFileName
End Sub
 
W

witek

Function BrowseFile() As String


Dim obOpenDialog As FileDialog
Set obOpenDialog = Application.FileDialog(msoFileDialogOpen)
While obOpenDialog.Filters.Count > 0
obOpenDialog.Filters.Delete
Wend
With obOpenDialog
.InitialFileName = "C:\"
.AllowMultiSelect = False
.Filters.Add "MS Access database", "*.mdb", 1
.Filters.Add "All files", "*.*", 2
.Show

If .SelectedItems.Count > 0
BrowseFile = .SelectedItems(1)

else
BrowseFile = ""
end if
End With

End Function
 
R

Ron de Bruin

Note: that GetOpenFilename is working in 97-2007 and FileDialog not (2002>)

Dim FName As Variant
Dim wb As Workbook
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir

MyPath = "C:\Data"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls")
If FName <> False Then
Set wb = Workbooks.Open(FName)
MsgBox "your code"
wb.Close
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir
 

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