Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error Handling
I am in need of some help with Error Handling. I am new to using VBA and
have found this site to be very helpful, but just cannot find enough information on error handling to make this make sense to me. My situation is as follows: I have a Scheduled task that opens a workbook containing the following code: AutoOpen Macro Sub Auto_Open() newHour = Hour(Now()) newMinute = Minute(Now()) newSecond = Second(Now()) + 3 waitTime = TimeSerial(newHour, newMinute, newSecond) Application.Wait waitTime SendKeys ("{TAB}") SendKeys ("~") On Error GoTo errhandler Workbooks.Open ("C:\Documents and Settings\dminor\Desktop\query\Dispatch Query.dqy") errhandler: If Err.Number = 1004 Then Application.DisplayAlerts = False Application.EnableEvents = False ActiveWorkbook.Close SaveChanges:=False Application.Quit End If Resume Next newHour = Hour(Now()) newMinute = Minute(Now()) newSecond = Second(Now()) + 10 waitTime = TimeSerial(newHour, newMinute, newSecond) Application.Wait waitTime Application.Run ("Personal.XLS!PriorityDispatch") Application.DisplayAlerts = True End Sub I have two issues with this code. The first is it only addresses the most common error, (error 1004), but every now and then I do see another type of error. The other issue is when I do experience the 1004 error Excel will close everything except my personal workbook. My questions are how I address all types of errors, and how I can close all of the workbooks. Any help would be appreciated. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error Handling
hi
basicly you need an error handler for each error you want to handle. identifing the error is the key. then you would do something like this..... errhandler: If Err.Number = 1004 Then do somthing else if err.number = 5 then do something else else if err.number = 3074 then do something else end if end if end if regards FSt1 "Dave M." wrote: I am in need of some help with Error Handling. I am new to using VBA and have found this site to be very helpful, but just cannot find enough information on error handling to make this make sense to me. My situation is as follows: I have a Scheduled task that opens a workbook containing the following code: AutoOpen Macro Sub Auto_Open() newHour = Hour(Now()) newMinute = Minute(Now()) newSecond = Second(Now()) + 3 waitTime = TimeSerial(newHour, newMinute, newSecond) Application.Wait waitTime SendKeys ("{TAB}") SendKeys ("~") On Error GoTo errhandler Workbooks.Open ("C:\Documents and Settings\dminor\Desktop\query\Dispatch Query.dqy") errhandler: If Err.Number = 1004 Then Application.DisplayAlerts = False Application.EnableEvents = False ActiveWorkbook.Close SaveChanges:=False Application.Quit End If Resume Next newHour = Hour(Now()) newMinute = Minute(Now()) newSecond = Second(Now()) + 10 waitTime = TimeSerial(newHour, newMinute, newSecond) Application.Wait waitTime Application.Run ("Personal.XLS!PriorityDispatch") Application.DisplayAlerts = True End Sub I have two issues with this code. The first is it only addresses the most common error, (error 1004), but every now and then I do see another type of error. The other issue is when I do experience the 1004 error Excel will close everything except my personal workbook. My questions are how I address all types of errors, and how I can close all of the workbooks. Any help would be appreciated. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Error Handling | Excel Discussion (Misc queries) | |||
Error Handling | Excel Programming | |||
Error handling with a handling routine | Excel Programming | |||
error handling off?? | Excel Programming | |||
Error Handling | Excel Programming |