ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error Handling (https://www.excelbanter.com/excel-programming/390807-error-handling.html)

Kirk P.

Error Handling
 
I've got this code:

Sub TimeCTSProcess()
Dim sglStartTime As Single
Dim sglEndTime As Single
Dim sglDuration As Single

sglStartTime = Timer
Call ProcessCTSWorkbooks
sglEndTime = Timer
sglDuration = Round(((sglEndTime - sglStartTime) / 60), 2)

MsgBox "CTS Eplanning Excel files processed in " & sglDuration & "
minutes!", _
vbInformation, "Processing Status"

End Sub

There is an error handler within ProcessCTSWorkbooks that works fine,
however I would prefer than when an error is encountered it would display the
msgbox associated with the error handler in ProcessCTSWorbooks and exit the
sub. Currently, I get the error message associated with ProcessCTSWorkbooks,
AND the message box associated with TimeCTSProcess.

tissot.emmanuel

Error Handling
 
Hi,

Change your ProcessCTSWorkbooks like this:

Sub ProcessCTSWorkbooks()
On Error GoTo ErrorHandler
'statements
Exit Sub
ErrorHandler:
MsgBox "An error occured in ProcessCTSWorkbooks"
End '<<<<< This keyword will stop the program
End Sub

Regards,

Manu/

"Kirk P." a écrit dans le message de news:
...
I've got this code:

Sub TimeCTSProcess()
Dim sglStartTime As Single
Dim sglEndTime As Single
Dim sglDuration As Single

sglStartTime = Timer
Call ProcessCTSWorkbooks
sglEndTime = Timer
sglDuration = Round(((sglEndTime - sglStartTime) / 60), 2)

MsgBox "CTS Eplanning Excel files processed in " & sglDuration & "
minutes!", _
vbInformation, "Processing Status"

End Sub

There is an error handler within ProcessCTSWorkbooks that works fine,
however I would prefer than when an error is encountered it would display
the
msgbox associated with the error handler in ProcessCTSWorbooks and exit
the
sub. Currently, I get the error message associated with
ProcessCTSWorkbooks,
AND the message box associated with TimeCTSProcess.




Kirk P.

Error Handling
 
That's what I like - a simple fix!

Thanks.

"tissot.emmanuel" wrote:

Hi,

Change your ProcessCTSWorkbooks like this:

Sub ProcessCTSWorkbooks()
On Error GoTo ErrorHandler
'statements
Exit Sub
ErrorHandler:
MsgBox "An error occured in ProcessCTSWorkbooks"
End '<<<<< This keyword will stop the program
End Sub

Regards,

Manu/

"Kirk P." a écrit dans le message de news:
...
I've got this code:

Sub TimeCTSProcess()
Dim sglStartTime As Single
Dim sglEndTime As Single
Dim sglDuration As Single

sglStartTime = Timer
Call ProcessCTSWorkbooks
sglEndTime = Timer
sglDuration = Round(((sglEndTime - sglStartTime) / 60), 2)

MsgBox "CTS Eplanning Excel files processed in " & sglDuration & "
minutes!", _
vbInformation, "Processing Status"

End Sub

There is an error handler within ProcessCTSWorkbooks that works fine,
however I would prefer than when an error is encountered it would display
the
msgbox associated with the error handler in ProcessCTSWorbooks and exit
the
sub. Currently, I get the error message associated with
ProcessCTSWorkbooks,
AND the message box associated with TimeCTSProcess.






All times are GMT +1. The time now is 10:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com