How can I successfully pass an error code from the VBA module in Part 2 to the VBScript that executed it in Part 1?
Part 1: VBScript that executes the VBA in Part 2
Option Explicit
Dim xlApp
Dim xlBook
If Err.Number <> 0 Then Err.Clear
Set xlApp = GetObject("","Excel.Application")
Set xlBook = xlApp.Workbooks.Open("\\(directory)\(File Name).xlsm", 0, True)
xlApp.Run "(Macro Name)"
If Err.Number <> 0 Then
Msgbox Err.Number & ": " & Err.Description & " The script will now quit."
WScript.Quit
Else
Msgbox Err.Number
End If
xlApp.Quit
Part 2: VBScript that executes the VBA in Part 2
Option Explicit
Sub (MacroName)()
'Snip - A bunch of working code
Err.Number = 7
Err.Description = "Made up error for testing - delete me"
End Sub
When this script is run, Err.Number is 0 when tested, and the Msgbox simply displays 0. What do I need to do to get it to display 7: Made up error for testing - delete me The script will now quit.
exceltag, but if you can point me to some meta that says we should use broader tagging in addition to narrower tagging I will approve the edit. I don't know what the meta verdict on the topic is.SuborFunctionprocedures to run, since it's a "script".