Sub CommandButton1_Click()
Dim fd As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.InitialFileName = ThisWorkbook.Path
.AllowMultiSelect = False
.Title = "Please select the file."
.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
UserForm1.TextBox1.Value = .SelectedItems(1) 'replace txtFileName with your textbox
End If
End With
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.InitialFileName = ThisWorkbook.Path
.AllowMultiSelect = False
.Title = "Please select the file."
.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
UserForm1.TextBox1.Value = .SelectedItems(1) 'replace txtFileName with your textbox
End If
End With
End Sub
No comments:
Post a Comment