Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tom tom is offline
external usenet poster
 
Posts: 570
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Handling - Check a file isn't already open before overwritin NDBC Excel Discussion (Misc queries) 4 August 13th 09 08:36 AM
Problem with handling on error when file is already open Frank Excel Programming 3 September 22nd 06 04:26 PM
workbooks.open and error handling John Keith[_2_] Excel Programming 5 August 18th 05 05:16 PM
Excel 2003 Workbooks.Open with CorruptLoad=xlRepairFile fails on Excel 5.0/95 file due to Chart, with Error 1004 Method 'Open' of object 'Workbooks' failed Frank Jones Excel Programming 2 June 15th 04 03:21 AM
Error Handling Open Function or query for missing Files BigNate Excel Programming 3 June 11th 04 05:22 PM


All times are GMT +1. The time now is 04:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"