excel - 如何使用 VBA Excel 2007 确定文件是否存在?

标签 excel vba

我正在尝试重写一些使用 Excel 2003 VBA 的 FileSearch 的代码。我正在尝试调用一个应确定 1 或 0 的函数,并使用 If 语句执行一些代码或迭代到下一个文件。

我的函数没有返回正确的结果。

我的代码:

 Dim MyDir As String, Fn As String
 Dim MyFile As String

   MyDir = "C:Test\"
   Fn = "" & "" & Examiner & " " & MnName & " " & Yr & ".xls"
   MyFile = MyDir & """" & Fn & """"

    If FileThere(MyFile) Then
    MsgBox yes

    Else
    MsgBox Not there

    End If

    '''''''''''''''''
    Function FileThere(FileName As String) As Boolean
         FileThere = (Dir(FileName) > "")
    End Function

最佳答案

Sub a()

MsgBox "test1 " & FileThere("c:\test1.bat")
MsgBox "k1" & FileThere("c:\k1")

End Sub

Function FileThere(FileName As String) As Boolean
     If (Dir(FileName) = "") Then
        FileThere = False
     Else:
        FileThere = True
     End If
End Function

关于excel - 如何使用 VBA Excel 2007 确定文件是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4082539/

相关文章:

excel - 根据单个列计算行数,以及多列的总和

excel - 如何为一张索引表中的每个工作表创建一个超链接?

VBA Excel - 组合多个自动过滤器

excel - 下标超出范围 IF ISERROR 问题

excel - 选择所有有数据的单元格

vba - 获取幻灯片形状对应的布局形状

excel - VBA调用SAP事务

excel - 为什么我会收到此编译错误 : Type Mismatch

excel - F#,Office 中的另一个 VBA?

vba - 当变量设置为新对象时,VBA 对象是否会被销毁?