【问题标题】:How Do I Determine If File Exists Using VBA Excel 2007?如何使用 VBA Excel 2007 确定文件是否存在?
【发布时间】:2011-05-04 05:02:37
【问题描述】:

我正在尝试重写一些使用 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

【问题讨论】:

    标签: excel vba


    【解决方案1】:
    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      • 2019-10-16
      • 2022-01-14
      • 2014-11-05
      • 2016-06-13
      相关资源
      最近更新 更多