Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / December 2007

Tip: Looking for answers? Try searching our database.

Error handling on Workbooks.Open

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tom - 07 Dec 2007 15:53 GMT
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?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.