You need to add a reference to the Microsoft Office Object Library for your version. The FileDialog object is in there. From there you can use it to use the standard Windows File Open dialog to select a file and store the path in a variable that can be used
n the TransferSpreadsheet method.
Following is code I use for this task:
Private Sub cmdBrowseForFile_Click()
On Error GoTo Err_cmdBrowseForFile_Click
Dim fDialog As Office.FileDialog
Dim varfile As Variant
Dim strPath As String
Dim strFilter As String, strFilename As String
' Requires reference to Microsoft Office x.xx Object Library.
strPath = CurrDBDir()
' Clear listbox contents.
' Me.FileList.RowSource = ""
' Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Allow user to make multiple selections in dialog box
' .AllowMultiSelect = True
' Set the title of the dialog box.
.Title = "Please select one or more files"
.InitialFileName = strPath
' Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Excel Files", "*.XLS*"
.Filters.Add "Text Files", "*.TXT"
.Filters.Add "CSV Files", "*.CSV"
' .Filters.Add "Excel Files", "*.XLSX"
' .Filters.Add "Access Databases", "*.MDB"
' .Filters.Add "Access Projects", "*.ADP"
' .Filters.Add "All Files", "*.*"
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
'Loop through each file selected and add it to our list box.
For Each varfile In .SelectedItems
Me.txtFilename = varfile 'Assigns selected path and file to control on a form.
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
'
''Sets filter for acceptable file types
' strFilter = ahtAddFilterItem(strFilter, "Import Files (*.xls,*.dbf,*.csv,*.mdb)", "*.XLS;*.DBF;*.CSV;*.MDB")
'
''Calls module to load File open dialog box for A: drive and selected File types
'strInputFileName = ahtCommonFileOpenSave(InitialDir:="H:\Accutrac\Accutrac Access\Imports", _
' Filter:=strFilter, OpenFile:=True, Flags:=ahtOFN_HIDEREADONLY, _
' DialogTitle:="Select File for Input...")
'
''Checks for valid selection and stores path
'If strInputFileName <> "Cancel" Then
' Me.txtFilename = strInputFileName
' If Right(strInputFileName, 3) = "mdb" Then
' Me!strTable.Visible = True
' Else
' Me!strTable.Visible = False
' End If
'End If
Exit_cmdBrowseForFile_Click:
Exit Sub
Err_cmdBrowseForFile_Click:
MsgBox Err.Description
Resume Exit_cmdBrowseForFile_Click
End Sub
Note: this code writes the path and file to a control on the form (Me.txtFilename), You can assign it to a variable instead and add the TransferSpreadsheet method.