Workbooks.Open ("H:\Checklist 07-23-07.xls")
Workbooks("CheckList.xls").Activate
What would be the best way to handle the error if the file does not exist?
Joel - 07 Dec 2007 15:59 GMT
filename = Dir(("H:\Checklist 07-23-07.xls")
if filename = <> then
'enter errror code
else
Workbooks.Open ("H:\Checklist 07-23-07.xls")
end if
> Workbooks.Open ("H:\Checklist 07-23-07.xls")
> Workbooks("CheckList.xls").Activate
>
> What would be the best way to handle the error if the file does not exist?
JE McGimpsey - 07 Dec 2007 16:00 GMT
The "best way" will depend on what you want to happen if the file
doesn't exist (e.g., do you want to exit the sub silently? Put up an
error message? invoke a dialog to find the file?).
One of the simplest:
Dim wkbk As Workbook
On Error Resume Next
Set wkbk = Workbooks.Open("H:\Checklist 07-23-07.xls")
On Error GoTo 0
If wkbk Is Nothing Then Exit Sub
...
> Workbooks.Open ("H:\Checklist 07-23-07.xls")
> Workbooks("CheckList.xls").Activate
>
> What would be the best way to handle the error if the file does not exist?