Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default 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
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 Kevin Excel Discussion (Misc queries) 4 June 19th 08 12:31 AM
Error Handling Steph[_6_] Excel Programming 1 August 25th 05 03:44 PM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM
error handling off?? Tom Ogilvy Excel Programming 0 August 19th 04 04:31 PM
Error Handling Bill Lunney Excel Programming 0 August 6th 03 11:56 PM


All times are GMT +1. The time now is 04:55 AM.

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

About Us

"It's about Microsoft Excel"