Run Excel macro from VB Script, but don't request VBA runtime errors

I would like to run the Excel macro from a VB script, but without the VBA that ever produced an error message at runtime, even if the macro has an intact runtime error.

Ideally, I want to capture the actual error message at runtime, but I would be happy to be able to resume the script without interacting with the dialog.

Here is a minimal example of what I'm talking about.

test.vbs:

Option Explicit 

Dim Excel: set Excel = CreateObject("Excel.Application")
Dim wb: set wb = Excel.Workbooks.Open("C:\Temp\test.xls")

On Error Resume Next
Excel.run "Hello"
On Error Goto 0

wb.Close
Excel.Quit

Inside module 1 of an Excel table called test.xls:

Option Explicit

Sub Hello()
    Dim x As Integer
    x = 1 / 0 ' Just causing an error for this example purposes
End Sub

. , , , , , , , .

Stackoverflow , Excel VB, - , VBA.

+4
1

, Inlcude On Error Resume Next Sub rountine

Sub Hello()
On Error Resume Next
' Please include the error statement after sub routine.
    Dim x As Integer
    x = 1 / 0 ' Just causing an error for this example purposes
End Sub
+1

Source: https://habr.com/ru/post/1682090/


All Articles