File Doesn't Exist Error Checking Code Not Working Properly

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,570
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am using this code to open a workbook. It first checks to see if such a file exists. If the file exists, it will open it. If it doesn't it will advise the user.

Rich (BB code):
    ftr = format(usd, "mmm-dd (ddd)") & " schedule_5.xlsx"
    If Dir("U:\PWS\Parks\Parks Operations\Sports\Sports17\DATA\" & ftr) = "" Then
        Workbooks.Open Filename:="U:\PWS\Parks\Parks Operations\Sports\Sports17\DATA\" & ftr
    Else
        ur1 = MsgBox("There is no data file associated with this date." & Chr(13) & "Do you wish to manually enter shift information?", 36, "DATA ERROR")
        If ur1 = vbNo Then
            uf9_poststaff.MultiPage1.Value = 0
            Unload uf9c_idate
        Else
            MsgBox "FUTURE"
        End If
    End If

I suspect my error checking code in purple isn't working. When ftr = "May-23 (Tue) schedule_5.xlsx", the error checking line incorrectly identifies the file as existing. There is no file ... there is "May-23 (Tue) schedule_3.xlsx", but not "May-23 (Tue) schedule_5.xlsx". If ftr = "Jan-23 (Wed) schedule_5.xlsx", and there isn't anything remotely close to that in the directory, the error checking code properly identifies it as not existing.

Where have I gone wrong, and what could I do to resolve the unexpected results?
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I suspect you need a If Not Dir in there. It looks like you affirm the file ISNT there then try to open it.
 
Upvote 0
Thank you both for your replies! I tried them both, and got similar positive results. It appears as though you fixed things up for me. Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top