I am trying to make an open dialog box that when you click the button it prompts you to select a file, and then has a message box staying what file you selected and the file path. for some reason i cant find the code to make it display the file name and path.
Here is what i have:
Private Sub cmdOpen_Click()
'Requires reference to Microsoft Office 10.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
'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 = False
'Set the title of the dialog box.
.Title = "Please select one 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
'msgbox you selected this file and at this path.
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub
it doesnt seem that hard yet im having toubles with it.
thanks.
Here is what i have:
Private Sub cmdOpen_Click()
'Requires reference to Microsoft Office 10.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
'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 = False
'Set the title of the dialog box.
.Title = "Please select one 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
'msgbox you selected this file and at this path.
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub
it doesnt seem that hard yet im having toubles with it.
thanks.