Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running a QM exe from Excel - and RT errors
#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


Messages In This Thread

Forum Jump:


Users browsing this thread: 4 Guest(s)