Hi,
I am trying to check if a file exists and then return an error message if it does not, however this is not working and the code is continuing regardless of weather or not the file is there.
Any hlep greatly appriciated
Thanks,
David
CheckFile = FilePath & FileName If CheckFile = "" Then MsgBox "The file Employee Change Updates could not be found." Exit Sub End If
CharlizeSub check_file() Dim mypath As String Dim myfiletocheck As String Dim myfile As String myfile = Dir(mypath & Application.PathSeparator & myfiletocheck) If myfile <> vbNullString Then MsgBox myfile & " is present", vbInformation Else MsgBox "The file : " & myfile & " is not available.", vbExclamation End If End Sub
Good morning duckboy1981
Alternatively you could write it as a function and call as required :
HTHPrivate Function DoesFileExist(FleNme) As Boolean DoesFileExist = (Dir(FleNme) <> "") End Function Sub test() If DoesFileExist("D:\Work\MyFile.xls") = True Then ' ... Your code here ... End If End Sub
DominicB
Sweet, nice and easy - just what i needed! Thanks
Hi,
If (FilePath & Filename) <> "" Then MsgBox "File Employee Change Exists" Else MsgBox "File Employee Change doesn't exist" End If
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks