View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Robert Crandal Robert Crandal is offline
external usenet poster
 
Posts: 309
Default Workbooks.Open() error handling

What does the "On Error Goto 0" code do?? Is is required as part
of the "On Error Resume Next" line?

thankx


"Per Jessen" wrote in message
...
Hi

Use the error handler to avoid the crash, and assign the opened workbook
to a variable, so you can test if it was opened.

Dim MyBook As Workbook
On Error Resume Next
Set MyBook = Workbooks.Open("mybook.xlsm")
On Error GoTo 0

If MyBook Is Nothing Then
MsgBox "Sorry, the file was NOT found! Try again!"
' Then ask user to select a new file
Else
MsgBox "File was found and opened"
End If