Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Error Trapping from WSH
Hi all,
I encountered a great difficulties in Automation with error handling and hope to seek helps from all of you: 1) A Excel workbook is created to include a module contain the following sub which raise an error: Const MY_ERROR As Long = 4567 Public Sub raiseError() On Error Resume Next Err.Raise MY_ERROR, , "This is my error." End Sub 2) Another WScript is used to invoke that function using Excel.Application: Public Sub abc() On Error Resume Next Dim xl Set xl = CreateObject("Excel.Application") xl.Visible = True Dim file file = Join(Array(WScript.ScriptFullName, "..", "MyExcel.xls"), "\") xl.Workbooks.Open file xl.Run "raiseError" If Err.Number < 0 Then Msgbox Err.Description End If xl.Quit End Sub However, the above example fails to trap the errors occured in the Excel. Could anyone would have experience to resolve it issues? Thanks a lot. Tom |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Error Trapping from WSH
Sorry all. The line "On Error Resume Next" in raiseError() should be
commented to illustrate the problem. Tom Chau wrote: Hi all, I encountered a great difficulties in Automation with error handling and hope to seek helps from all of you: 1) A Excel workbook is created to include a module contain the following sub which raise an error: Const MY_ERROR As Long = 4567 Public Sub raiseError() On Error Resume Next Err.Raise MY_ERROR, , "This is my error." End Sub 2) Another WScript is used to invoke that function using Excel.Application: Public Sub abc() On Error Resume Next Dim xl Set xl = CreateObject("Excel.Application") xl.Visible = True Dim file file = Join(Array(WScript.ScriptFullName, "..", "MyExcel.xls"), "\") xl.Workbooks.Open file xl.Run "raiseError" If Err.Number < 0 Then Msgbox Err.Description End If xl.Quit End Sub However, the above example fails to trap the errors occured in the Excel. Could anyone would have experience to resolve it issues? Thanks a lot. Tom |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|