The approach should be to add an error handler that has code to handle this particular error.
You add to the routine that opens the file, at the top,
On Error GoTo Er. (That "Er" is a label in the same routine. You can call the label whatever you like. I like Er...)
Then at the botom of your code, add an exit that will cause program flow to exit the routine prior to the label Er when there is no error. You can use this exit point when there
is an error if you add a lable just before the exit point. (Again, whatever you like, but I like Rs for "resume" point.)
Then, after the label in the On Error statement, handle the error. Let's presume the error is 15. THen the code would be something like:
Code:
Public Sub Whatchamo()
On Error GoTo Er
' Your code here that might raise the error.
Rs: ' Do any cleanup here, closing files, etc.
Exit Sub
Er:
If Err.Number = 15 Then
MsgBox "The file " & <put FilNam here, so msg is informative> & " " & _
"could not be opened.", vbCritical, "File Open Error"
Else
MsgBox "Error " & Err.Description, vbCritical, "Error"
End If
Resume Rs
Exit Sub