Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running a QM exe from Excel - and RT errors
#1
I'm runing a simple QM generated exe macro from an Excel macro as follows:

Dim RetVal
RetVal = Shell("E:\RUN\QMMACRO.EXE", 1)

My question is how do I detect when a QM macro RT error occurs - specifically the QM macro enters a number in a window and clicks on a submit button, but when that window is not there, QM logs the error OK in its debug window. But I want to be able to detect this in my Excel macro also by some return value.

When I check the value of "RetVal" above in my Excel macro, even when a window not found error happens, it is always a positive value such as 2238 4468 etc....


Thanks for any help.
#2
To return error/success status, exe files use an exit code.
To set an exit code, simply return it from your exe-macro. Example: ret 1.
But VBA Shell() function does not give you the exit code.
Need to use some other function.

Run this macro once.
It creates a small dll "qmvbrun.dll" and puts it in your system folder. QM must be running as admin.
The dll has function VbRun. It runs a program (must be program, not document or folder etc), waits, and returns its exit code.
The function can be used in Excel macros and other VB or VBA code.
Macro Macro1497
Code:
Copy      Help
__Tcc x.Compile("" "$system$\qmvbrun.dll" 2)

#ret

#include <windows.h>

__declspec(dllexport)
int VbRun(LPSTR program, LPSTR cmdLine)
{
_spawnlp(0, program, " ", cmdLine, 0);
__asm__("leave;ret $8"); //make stdcall
}

Excel macro example
Code:
Copy      Help
Public Declare Function VbRun Lib "qmvbrun.dll" (ByVal program As String, Optional ByVal cmdLine As String) As Long

Sub main()
Dim RetVal
RetVal = VbRun("notepad.exe")
'RetVal = VbRun("Q:\My QM\Macro 1496.exe", "command line")
MsgBox RetVal
End Sub


Forum Jump:


Users browsing this thread: 1 Guest(s)