Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 122
Default error problem

Hi,

i have an application with lots of sheets, forms and modules and subs.
with each error i would like the following code to be executed:

private sub error()
With Sheets("waarschuwing")
Dim c As Integer
.Visible = xlSheetVisible
For c = 1 To Sheets.Count
If Sheets(c).Name < "waarschuwing" Then
Sheets(c).Visible = xlSheetVeryHidden
End If
Next
End With
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub

however, the sub is in a module.
I would like to have the on erro goto statement go to this sub in the error
handling module.
How can i do that in VBA?
Thanks,
Pierre


--
Message posted via http://www.officekb.com
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default error problem

First, you would need to make your sub Public, not Private, to be visible
across modules. Also, I would not name it Error() as that is a reserved word
in VBA causing potential confusion with the VBA built-in Error function. So
I will call it "MyError" here.

Then, in each function/sub where you wanted to use this as your error
handler, you could do as illustrated below:

Sub MySub()
On Error goto MyErrHandler

' Regular code for sub goes here

Exit Sub

MyErrHandler:
MyError
End Sub

Since your code closes the active workbook, I am assuming you do not need
any code to continue at that point, but if you do need to continue, put a
Resume Next statement after you call MyError:

MyErrHandler
MyError
Resume Next
End Sub

--
- K Dales


"Pierre via OfficeKB.com" wrote:

Hi,

i have an application with lots of sheets, forms and modules and subs.
with each error i would like the following code to be executed:

private sub error()
With Sheets("waarschuwing")
Dim c As Integer
.Visible = xlSheetVisible
For c = 1 To Sheets.Count
If Sheets(c).Name < "waarschuwing" Then
Sheets(c).Visible = xlSheetVeryHidden
End If
Next
End With
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub

however, the sub is in a module.
I would like to have the on erro goto statement go to this sub in the error
handling module.
How can i do that in VBA?
Thanks,
Pierre


--
Message posted via http://www.officekb.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 122
Default error problem

Thanks K.
This helps a lot !
Pierre

K Dales wrote:
First, you would need to make your sub Public, not Private, to be visible
across modules. Also, I would not name it Error() as that is a reserved word
in VBA causing potential confusion with the VBA built-in Error function. So
I will call it "MyError" here.

Then, in each function/sub where you wanted to use this as your error
handler, you could do as illustrated below:

Sub MySub()
On Error goto MyErrHandler

' Regular code for sub goes here

Exit Sub

MyErrHandler:
MyError
End Sub

Since your code closes the active workbook, I am assuming you do not need
any code to continue at that point, but if you do need to continue, put a
Resume Next statement after you call MyError:

MyErrHandler
MyError
Resume Next
End Sub

Hi,

[quoted text clipped - 21 lines]
Thanks,
Pierre



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200511/1
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 problem Ayo Excel Discussion (Misc queries) 11 May 20th 09 04:52 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Problem with #VALUE/0! error Ted Excel Worksheet Functions 2 November 22nd 05 03:37 PM
Unknown where is the problem on the Runtime error - Automation error wellie Excel Programming 1 July 10th 03 08:12 AM


All times are GMT +1. The time now is 04:59 PM.

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

About Us

"It's about Microsoft Excel"