Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default 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
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



All times are GMT +1. The time now is 08:31 AM.

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

About Us

"It's about Microsoft Excel"