ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can I place "On Error GOTO xxx" into module level? (https://www.excelbanter.com/excel-programming/349382-can-i-place-error-goto-xxx-into-module-level.html)

Frederick Chow

Can I place "On Error GOTO xxx" into module level?
 
Hi all,

Just have a question.

I have developed so many subroutines in many modules of a workbook,
including an error handling procedure which handles any unhandled errors..
Instead of writing an error-handling routine within all subroutines, is it
possible to write an error-handling routines once in a workbook so as to
apply to all other subroutines?

By the way, is there a syntax something like "On Error GoTo <Subroutine" or
"On Error GoSub ... " in VBA?

Thanks a lot.

Frederick Chow



Jim Thomlinson[_5_]

Can I place "On Error GOTO xxx" into module level?
 
In short no (to the best of my knowledge). Every sub must have an error
handler in it. However as to the second part of your question sure... I have
a standard error handling module that I use in all of my projects. I add the
module and my error handler just calls a sub within it. There are a bunch of
standard things like resetting the application level settings and a form is
displayed showing the nature of the error...

Private Sub TestStuff()
On Error GoTo ErrorHandler
'Your Code Here
Exit Sub

ErrorHandler:
modErrors.HandleError
End Sub
--
HTH...

Jim Thomlinson


"Frederick Chow" wrote:

Hi all,

Just have a question.

I have developed so many subroutines in many modules of a workbook,
including an error handling procedure which handles any unhandled errors..
Instead of writing an error-handling routine within all subroutines, is it
possible to write an error-handling routines once in a workbook so as to
apply to all other subroutines?

By the way, is there a syntax something like "On Error GoTo <Subroutine" or
"On Error GoSub ... " in VBA?

Thanks a lot.

Frederick Chow




Frederick Chow

Can I place "On Error GOTO xxx" into module level?
 
So is there a syntax like "On Error GoSub HandleError"? This should have
been much more convenient.


"Jim Thomlinson" wrote in
message ...
In short no (to the best of my knowledge). Every sub must have an error
handler in it. However as to the second part of your question sure... I
have
a standard error handling module that I use in all of my projects. I add
the
module and my error handler just calls a sub within it. There are a bunch
of
standard things like resetting the application level settings and a form
is
displayed showing the nature of the error...

Private Sub TestStuff()
On Error GoTo ErrorHandler
'Your Code Here
Exit Sub

ErrorHandler:
modErrors.HandleError
End Sub
--
HTH...

Jim Thomlinson


"Frederick Chow" wrote:

Hi all,

Just have a question.

I have developed so many subroutines in many modules of a workbook,
including an error handling procedure which handles any unhandled
errors..
Instead of writing an error-handling routine within all subroutines, is
it
possible to write an error-handling routines once in a workbook so as to
apply to all other subroutines?

By the way, is there a syntax something like "On Error GoTo <Subroutine"
or
"On Error GoSub ... " in VBA?

Thanks a lot.

Frederick Chow







All times are GMT +1. The time now is 11:41 AM.

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