关闭文件资源管理器后出错

Error after closing file explorer

我创建了一个非常好的工作 vba 代码,用于从 windows 文件资源管理器导入 csv 文件。但是,当我在打开文件之前关闭资源管理器时,会弹出 1004 错误对话框。它说找不到刷新外部范围的文本文件。最下面的line line 应该是原因:

.Refresh BackgroundQuery:=False

有没有人知道如何摆脱这个错误?

Dim ClickCount As Integer

Sub CommandButton1_Click()

Dim sht As Worksheet
Dim LastRow As Long
Dim begin As String
Dim myInput As Long

ClickCount = ClickCount + 1

If ClickCount > 1 Then GoTo Line1 Else GoTo Line2

Line1:
myInput = MsgBox("Gebruikers zijn reeds geimporteerd. Records worden mogelijk dubbel opgeslagen. Wilt u toch doorgaan met importeren?", vbCritical + vbYesNo, "Import error")
    If myInput = vbYes Then
    GoTo Line2
    Else
    Exit Sub

Line2:

Set sht = ActiveSheet

  LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
begin = "$A" & "$" & LastRow + 1

Dim fileName
  fileName = Application.GetOpenFilename(FileFilter:="CSV Files (*.csv),*.csv")

    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;" & fileName, _
        Destination:=range(begin))
        .Name = "User import 1.0"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = True
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
  End If
End Sub
Dim fileName
fileName = Application.GetOpenFilename(FileFilter:="CSV Files (*.csv),*.csv")

If fileName = False then Exit Sub