How to handle open file errors in code?

  • Thread starter Thread starter M. Brane
  • Start date Start date
M

M. Brane

I've got an excel workbook that opens another file using:

On Error GoTo Missing
Workbooks.Open Filename:=fn, UpdateLinks:=False, ReadOnly:=True

When the file can't be opened, I'd like the code to handle the
situation. However, if the file can't be open, the user still gets a
pop-up saying the file can't be opened, do you want to continue?

Is there any way to supress that message to the user?
 
Dim wbkOpen As Workbook

On Error Resume Next
Set wbkOpen = Workbooks.Open(Filename:=fn, UpdateLinks:=False, _
ReadOnly:=True)
On Error GoTo 0

If wbkOpen Is Nothing Then
If MsgBox("file did not open. continue?", vbYesNo) = vbNo Then
MsgBox "All done"
Else
MsgBox "Keep on going"
End If
End If
 
Back
Top