LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Workbooks.Open() error handling

My VBA module contains the following code:

Workbooks.Open ("mybook.xlsm")

If "mybook.xlsm" does not exist, then my VBA code
will crash immediately and the user will see an error
dialog box, plus the VBA program will stop running as
well.

If Workbooks.Open() fails, can I somehow instruct
VBA to detour to some alternate code rather than
crashing?? For example, can I use code somewhat
similiar to below:

If Workbooks.Open("mybook.xlsm") = FILE_WAS FOUND? then
MsgBox "File was found and opened"
Else
MsgBox "Sorry, the file was NOT found! Try again!"
' Then ask user to select a new file
End If


thank u


 
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
Error handling on Workbooks.Open Tom Excel Programming 2 December 7th 07 04:00 PM
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


All times are GMT +1. The time now is 10:22 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"