关闭文件对话框应用程序

时间:2015-03-07 11:22:41

标签: excel vba excel-vba

我有这个代码。此代码打开文件浏览器。 但是,如果单击取消或关闭会出现错误。 因此我试着说:

 If Not IsEmpty(diaFolder.SelectedItems) Then 

但这不起作用。我该怎么办?

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

1 个答案:

答案 0 :(得分:0)

尝试改为:

If diaFolder.SelectedItems.Count <> 0 Then