小编Joh*_*hnM的帖子

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

我试图重写一些使用FileSearch for Excel 2003 VBA的代码.我试图调用一个应该确定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
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

5
推荐指数
1
解决办法
3万
查看次数

标签 统计

excel ×1

excel-vba ×1

vba ×1