ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to handle open file errors in code? (https://www.excelbanter.com/excel-programming/409145-how-handle-open-file-errors-code.html)

M. Brane

How to handle open file errors in code?
 
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?

Jim Thomlinson

How to handle open file errors in code?
 
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
--
HTH...

Jim Thomlinson


"M. Brane" wrote:

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?



All times are GMT +1. The time now is 10:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com