How to handle open file errors in code?

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?
 
J

Jim Thomlinson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top