Рет қаралды 13,980
Excel VBA Macro: Allow User to Select File to Open (with Dialog Box). In this video, we go over how to allow a user to be prompted to select a file and then open the selected file. We also change the title and button names in the Dialog Box and specify how many files the user is allowed to select.
Code:
Sub select_file()
Dim FilePicker As FileDialog
Dim mypath As String
Set FilePicker = Application.FileDialog(msoFileDialogFilePicker)
With FilePicker
.Title = "Please Select a File"
.AllowMultiSelect = False
.ButtonName = "Confirm"
If .Show = -1 Then
mypath = .SelectedItems(1)
Else
End
End If
End With
Workbooks.Open Filename:=mypath
End Sub
#ExcelVBA #ExcelMacro