Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Fortran exe from Excel.

Status
Not open for further replies.

dvulin

Petroleum
Mar 19, 2003
4
I have Excel sheets and small Fortran application. I made a VBA macro that saves input data for Fortran exe into a .txt file.
After that, I used Shell function in VBA macro tu execute FOR application and there is no error message, but there's neither a output TXT file that this FOR application usually creates.
I looked in the folder where are all the files (Workbook, input TXT that macro created, Fortran EXE) and there is no output TXT file. Then, if I started that Fortran.exe from windows it creates the output file from that input file that I already created using the mentioned macro.
I tried to find more about Shell function, but there is only a simple example that starts calc.exe from VBA macro.

However, here is the critical part of code:
...
Set filFile = fso_OpenTextFile(f & "\input.txt", 2, 1)
filFile.WriteLine MP
filFile.Close
Set filFile = Nothing
Set fso = Nothing
MyRun = Shell(f & "\test_dll.exe", 1)

Maybe the Shell function starts before the input.txt file is actually closed, i don't know...

Thanks in advance




 
Replies continue below

Recommended for you

Why can't you test the running of the program with an existing file to pinpoint the problem? Maybe you should put a test for the existence of the file before you allow the program to start.

I've done similar things using Excel to transfer input data to Word, Word for editing the input file, running a Fortran program, opening the output file in Word and transferring the data into Excel

TTFN
 
Do you do anything after running the Shell method? Do you need to wait until the exe is finished before continuing your macro? There should not be a problem running the exe as you have shown, for the file will close before it's run.

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
The file will close in Excel fairly quickly, but there are often delays in the OS before the file gets fully instantiated in the file directory.

TTFN
 
I just had the same problem with an old dos based fortran exe. I solved the problem by making sure the input file and fortran program were in excel's current directory. Then i used the command shell("blah.exe") and the program ran. The VBA code continues to run after your fortran code starts so you also have to command VBA to wait for it to finish if you need to deal with any output files.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor