Excel VBA - How to Get File using File Dialog Box

Опубликовано: 01 Октябрь 2024
на канале: InAnOffice
42,947
329

Excel VBA Learn how to get selected path of the file using file dialog box

The code used in this video:

Sub GettingFile()
Dim SelectedFile As String

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Title = "Select file"
.ButtonName = "Confirm"
.InitialFileName = "C:\"
If .Show = -1 Then
'ok clicked
SelectedFile = .SelectedItems(1)
MsgBox SelectedFile
Else
'cancel clicked
End If

End With


End Sub