![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: John G
Posts: 62
|
What types of events or code would you put an on error in? I have an application that opens and closes another workbook, saves, and switches betweeen different sheets quite a bit. Is there somewhere I can go to find out more about "on error" and how to correctly use it?
John |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Posts: 3,065
|
Hi
try the VBE help file ERRORS Error Statement Example This example uses the Error statement to simulate error number 11. On Error Resume Next ' Defer error handling. Error 11 ' Simulate the "Division by zero" error. """""""" Error Object, Errors Collection, and Description, Number, Source, HelpFile, and HelpContext Properties Example This example forces an error, traps it, and displays the Description, Number, Source, HelpContext, and HelpFile properties of the resulting Error object. Sub DescriptionX() Dim dbsTest As Database On Error GoTo ErrorHandler ' Intentionally trigger an error. Set dbsTest = OpenDatabase("NoDatabase") Exit Sub ErrorHandler: Dim strError As String Dim errLoop As Error ' Enumerate Errors collection and display properties of ' each Error object. For Each errLoop In Errors With errLoop strError = _ "Error #" & .Number & vbCr strError = strError & _ " " & .Description & vbCr strError = strError & _ " (Source: " & .Source & ")" & vbCr strError = strError & _ "Press F1 to see topic " & .HelpContext & vbCr strError = strError & _ " in the file " & .HelpFile & "." End With MsgBox strError Next Resume Next End Sub :::::::::: that sort of thing what you looking for?
__________________
Free Excel based Web Toolbar available here. Jack in the UK J & R Excel Solutions "making Excel work for you" |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
Nice explanation Jack !
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|