VBA:运行时错误55-文件已打开(使用文件对话框)

VBA:运行时错误55-文件已打开(使用文件对话框),vba,ms-access,import,runtime-error,text-files,Vba,Ms Access,Import,Runtime Error,Text Files,在VBA Ms Access中,我导入一个txt文件,逐行解析它 我使用一个文件对话框,用户可以选择要导入的文件,但是当我打开文件读取它时,我得到一个运行时错误55-文件已经打开 cose是: Dim openDialog As FileDialog Set openDialog = Application.FileDialog(msoFileDialogFilePicker) On Error GoTo DoNothing With openDialog .title = "Impor

在VBA Ms Access中,我导入一个txt文件,逐行解析它

我使用一个文件对话框,用户可以选择要导入的文件,但是当我打开文件读取它时,我得到一个运行时错误55-文件已经打开

cose是:

Dim openDialog As FileDialog

Set openDialog = Application.FileDialog(msoFileDialogFilePicker)
On Error GoTo DoNothing
With openDialog
   .title = "Import"
   .AllowMultiSelect = False
   .Show
End With

FName = openDialog.SelectedItems.Item(1)
'Close FName

Open FName For Input Access Read As #1
On Error GoTo DoNothing

相反,如果我使用Close Fname,则不会出现运行时错误,但导入不起作用(导入的代码是正确的,因为当我硬编码名称文件时它会起作用)

一旦有了文件名,请使用以下命令删除对话框处理程序:

Set openDialog = Nothing