How to call exe file in excel?

U

undisclosed

hi
I want to call exe file in excel using the VBA code
someone suggest me use the following code
RetVal = *Shell(*"C:\WINDOWS\CALC.EXE"*,* 1*),
but I find that this code cannot call the exe file to input and outpu
txt file
Is there any other way for me call the exe file so that it can at leas
output txt file

Thx
 
U

undisclosed

so there is no way to ask the excel to call an exe file with outpu
function
but i really need such process, are there any other suggestions fo
doing so
 
B

Bob I

What output a program or .exe is capable of depends on the program or
..exe file features, it has nothing to do with excel. You need research
the capabilities of the program in question.
 
S

Steve Rindsberg

so there is no way to ask the excel to call an exe file with output
function?

Yes, there is. But since you haven't told us what program you want to
call or what command line parameters it accepts, there's no way we can
tell you how to do this.

Generally, something like this, which'll open the specified file in
Notepad and print it to the current default printer driver using the /p
command line parameter:

Dim RetVal As Double
Dim Program As String
Dim Params As String

Program = "NOTEPAD.EXE"
Params = "/p c:\path\filename.ext"

RetVal = Shell(Program & " " & Params, vbNormalFocus)
 
U

undisclosed

Here is my test code for the exe file using the dev-C++

-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
 

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