2010-11-02 11 views
5

Estoy intentando reescribir algún código que estaba utilizando FileSearch para Excel 2003 VBA. Estoy intentando llamar a una función que debería determinar 1 o 0 y usando una declaración If ejecutaré algún código o repetiré el siguiente archivo.¿Cómo puedo determinar si existe un archivo con VBA Excel 2007?

No devuelvo el resultado correcto de mi función.

Mi código:

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 

Respuesta

9
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 
+0

Muchas gracias. – JohnM

Cuestiones relacionadas