Intriguing
Intriguing

Reputation: 59

Close File Dialog Application

I have this code. This code opens the file browser. But if you click Cancel or Close appears an error. For this reason I try to put:

 If Not IsEmpty(diaFolder.SelectedItems) Then 

But this doesn't work. What should I do?

Private Sub Image1_Click()
Dim diaFolder As FileDialog
' Open the file dialog
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
diaFolder.AllowMultiSelect = False
diaFolder.Show

If Not IsEmpty(diaFolder.SelectedItems) Then
    Cells(1, 1) = diaFolder.SelectedItems(1)
    TextBox1 = diaFolder.SelectedItems(1)
End If

Set diaFolder = Nothing
End Sub

Upvotes: 0

Views: 1304

Answers (1)

Ralph J
Ralph J

Reputation: 478

Try instead:

If diaFolder.SelectedItems.Count <> 0 Then

Upvotes: 1

Related Questions