How to call a exe file with output txt file function in the excel?

U

undisclosed

Hello, I want to call exe file with the function of output txt file as
result in the excel using the VBA code

But I soon find that the code I have can only ask the exe to ru
smoothly but cannot ask the exe file to output txt file

Is there any other way for me call the exe file so that it can at leas
output txt file

The follwowing is my code

-Test.exe
-#include <cstdlib
#include <iostream
#include <stdio.h
#include <fstream
#include <string>
-using namespace std;
-int main(int argc, char *argv[]

ofstream output("test.txt")
output<<2<<endl
system("PAUSE")
return EXIT_SUCCESS
}

I ask the programe to output a txt file containing the no. "2

Then I ues this in the VBA in excel

-Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVa
hProcess As Long, lpExitCode As Long) As Lon

-Public Declare Function OpenProcess Lib "kernel32" (ByVa
dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessI
As Long) As Long

-Public Const STILL_ACTIVE = &H10

-Public Const PROCESS_QUERY_INFORMATION = &H40

-Sub Run_de()

-sCmd = ThisWorkbook.Path & "\" & "Test.exe
vntResult = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell (sCmd
1)
GetExitCodeProcess vntResult, lngExitCode

-D
GetExitCodeProcess vntResult, lngExitCod
DoEvent
Loop While lngExitCode = STILL_ACTIVE

-End Sub

When I press the test.exe alone, the programe can function well an
output the test.txt in the same folder as the excel. However, when I us
the excel to call the exe, no such test.txt will be printed out

Can anyone help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top