查找具有 vba 访问权限的现有文件

Finding an existing file with access vba

我正在尝试在文件夹位置查找现有文件

当前代码:

Dim FileExistsbol As Boolean
Dim stFileName As String
stFileName = "H:\Test File.txt"
stFileName = Trim(stFileName)
FileExistsbol = dir(stFileName) <> vbNullString
If FileExistsbol Then Kill stFileName

错误:

错误信息是:类型不匹配 VBA 在此行调试:

FileExistsbol = dir(stFileName) <> vbNullString

该文件确实存在,所以不确定如何解决这个问题 - 有什么想法吗?

我会去掉 FileExistsbol 变量,然后做类似的事情:

If Dir(stFileName) <> "" Then
    Kill stFileName
End If