This is what I think is the best method for determining if a
file exists or not. Just pass the filepath and name as a string.
VB/Outlook Guru!VB Code:
Option Explicit Private Const OF_EXIST = &H4000 Private Const OFS_MAXPATHNAME = 128 Private Type OFSTRUCT cBytes As Byte fFixedDisk As Byte nErrCode As Integer Reserved1 As Integer Reserved2 As Integer szPathName(OFS_MAXPATHNAME) As Byte End Type Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long Public Function FileExists(ByVal sFile As String) As Long Dim lRetVal As Long Dim OfSt As OFSTRUCT lRetVal = OpenFile(sFile, OfSt, OF_EXIST) If lRetVal = 1 Then FileExists = 1 Else FileExists = 0 End If End Function 'Usage: Private Sub Command1_Click() If FileExists("C:\DeleteMe\Test.txt") = 1 Then Msgbox "File Exists!" Else 'MsgBox "File Not Found!" End If End Sub





Reply With Quote