Runing Fortran with VBA --- simulating enter key function

Javi

Active Member
Joined
May 26, 2011
Messages
440
Hi All,

What I'm trying to do is run Fortran with <acronym title="visual basic for applications">VBA</acronym> code. The code below will open a DOS window and prepare Fortran to run. however, it requires me to manual press the enter key. I have tried several attempts in writing in a simulated enter key stroke in the code but, I have been unsuccessful because the active window is Excel and not the DOS window. The output data from Fortran is automatically inserted into my sheet which will allow me to run this program in a loop until certain criteria is met.

I have tried to minimize the Excel window then have the enter key simulated after a time delay again unsuccessful.


the below is part of my code that runs Fortran.

Sub Fortran_Run()
RetVal = Shell("C:\Users\admin\Desktop\sim_code\FT_simulation.exe", 1)

'Application.WindowState = xlMinimized

'lcshl.SendKeys "{ENTER}" result unsuccessful
'Application.WindowState = xlMinimized

SendKeys String:="%slc{enter}", Wait:=True

Application.Wait (Now + TimeValue("00:00:10")) results successful however the active window needs to be the DOS window that Fortran is running in.

End sub


thank you in advance any help and or advice would be appreciated.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
This looks like it is exactly what I'm looking for. However I'm a little confused as to what to do with the sendkey file from the zip file I downloaded. if you have used this before can you please give me a little direction as to how to incorporate this into the code i.e. where to place the file.

Thank you for the advice I think we are on the right path.
 
Upvote 0
SendKeys.exe can be placed in any folder, but you must reference the full path as shown in the example.
 
Upvote 0
Thanks so Much for your help!! This is what I used and it's working great as of now. It is sending the enter key just as needed. The obstacle was getting the pause/sleep in, once I was successful in calling the sleep macro everything worked perfectly.


Sub Fortran_Run()

Set X = CreateObject("wscript.shell")

'Change admin to your user name

RetVal = Shell("C:\Users\myUser\Desktop\my_code\my_simulation.exe", 1)

Call Sleep

X.SendKeys "{enter}"

End Sub

---------------------------------------------------------------

Sub Sleep()

'Puts a wait time

waitUntil = Now() + TimeValue("00:00:02")

While Now() < waitUntil
'DoEvents

Wend

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,734
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top