rrhandle8
asked on
Get file name an path using VBA
I have a browse button on an Excel form so user can select a file to load. The code below works great in Excel 2010, but causes a run-time error for users of Excel 2013.
Public Function ChooseFile() As String
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Show Windows Dialog box for users to choose an Item file.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim fd As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
' Set the title of the dialog box.
.Title = "Please select the file."
' Clear out the current filters, and add our own.
.Filters.Clear
.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
ChooseFile = .SelectedItems(1)
txtFileName = .SelectedItems(1) 'replace txtFileName with your textbox
Debug.Print "From dialog " & txtFileName
End If
End With
End Function
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER