Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50057

How to use FileDialog in Excel VBA?

$
0
0
Hi,

In Excel VBA, I use the following code to show the FileDialog box and select a new folder:

Private Sub CommandButton1_Click()
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = ThisWorkbook.Path
.Show
TextBox1 = .SelectedItems(1)
End With
End Sub

After the dialog box appears, if, however, I change mind and don't want to select a new folder and click the OK button or Cancel button, an error will pop up: "Path does not exist....". Any thing I am doing wrong?

Thank you in advance.

Viewing all articles
Browse latest Browse all 50057

Trending Articles