ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error handling on Workbooks.Open (https://www.excelbanter.com/excel-programming/402398-error-handling-workbooks-open.html)

tom

Error handling on Workbooks.Open
 
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

Error handling on Workbooks.Open
 
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

"Tom" wrote:

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

Error handling on Workbooks.Open
 
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
...

In article ,
Tom wrote:

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?



All times are GMT +1. The time now is 02:12 AM.

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