2010-11-02 16 views
5

Sto tentando di riscrivere un codice che utilizza FileSearch per Excel 2003 VBA. Sto tentando di chiamare una funzione che dovrebbe determinare 1 o 0 e utilizzando una dichiarazione If eseguirò del codice o eseguirò l'iterazione sul file successivo.Come determinare se il file esiste con VBA Excel 2007?

Non sto restituendo il risultato corretto dalla mia funzione.

Il mio codice:

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 

risposta

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

Grazie mille. – JohnM

Problemi correlati