使用VBA、excel关闭浏览器窗口

使用VBA、excel关闭浏览器窗口,excel,vba,Excel,Vba,Im使用GetFolder函数合并多个excel文件 Folder = GetFolder() Folder = Folder & "\" FName = Dir(Folder & "*.xl*") ... Function GetFolder() 'Declare a variable as a FileDialog object. Dim fd As FileDialog 'Create a FileDialog object as a Folder P

Im使用GetFolder函数合并多个excel文件

Folder = GetFolder()
Folder = Folder & "\"
FName = Dir(Folder & "*.xl*")
...

Function GetFolder()
     'Declare a variable as a FileDialog object.
  Dim fd As FileDialog

  'Create a FileDialog object as a Folder Picker dialog box.
  Set fd = Application.FileDialog(msoFileDialogFolderPicker)
  fd.Title = "Select Excel Workbook(s) Folder"
  'Declare a variable to contain the path
  'of each selected item. Even though the path is a String,
  'the variable must be a Variant because For Each...Next
  'routines only work with Variants and Objects.
  Dim vrtSelectedItem As Variant

  'Use a With...End With block to reference the FolderDialog object.
  With fd

    'Use the Show method to display the File Picker dialog box and return the user's action.
    'The user pressed the action button.
    If .Show = -1 Then

      'Step through each string in the FileDialogSelectedItems collection.
      For Each vrtSelectedItem In .SelectedItems

        'vrtSelectedItem is a String that contains the path of each selected item.
        'You can use any file I/O functions that you want to work with this path.
        'This example simply displays the path in a message box.
        GetFolder = vrtSelectedItem

      Next vrtSelectedItem
    'The user pressed Cancel.
    Else
    End If
  End With

  'Set the object variable to Nothing.
  Set fd = Nothing


End Function
当我激活该功能时,将打开一个Windows浏览器窗口,使我能够选择计算机上所需的文件夹,然后继续执行代码的其余部分。问题是,当我想关闭浏览器而不选择文件夹时,单击上角的“关闭”(X)按钮,窗口确实会关闭,但代码会继续运行,就像我选择了文件夹一样。
我怎样才能使它接近和“结束子”

在调用
GetFolder函数
之后,尝试简单地添加
If语句
,如下所示:

If IsEmpty(Folder) Then Exit Sub

在调用
GetFolder函数
之后,尝试简单地添加
If语句
,如下所示:

If IsEmpty(Folder) Then Exit Sub

我希望它在单击X(关闭)按钮时关闭,而不是在打开文件夹时关闭empty@user1040563,如果按X,则您的
文件夹变量
为空-这就是我检查的内容。我不检查你的文件夹中是否有任何内容。添加此行并检查它是否不是您要搜索的内容。我希望它在单击X(关闭)按钮时关闭,而不是在文件夹关闭时关闭empty@user1040563,如果按X,则您的
文件夹变量
为空-这就是我检查的内容。我不检查你的文件夹中是否有任何内容。添加此行并检查它是否不是您要搜索的内容。