![]() |
running command line programs from Excel
I have a program that I can presently only run using the command line window
(which used to be the MS-DOS window I guess). I would like to integrate this program with programs I've written in VBA. Is it possible to call "DOS" programs using VBA code? Help would be greatly appreciated. Cheers, Thomas |
running command line programs from Excel
Hi Thomas,
See the Shell funciton and example in CVBA help --- Regards, Norman "Thomas Moen" wrote in message ... I have a program that I can presently only run using the command line window (which used to be the MS-DOS window I guess). I would like to integrate this program with programs I've written in VBA. Is it possible to call "DOS" programs using VBA code? Help would be greatly appreciated. Cheers, Thomas |
running command line programs from Excel
One way is to put your DOS commands in a batch files and call this from Excel
Sub rundos() Call Shell("c:\test.bat", 1) End Sub Runs test.bat in the root of C Mike "Thomas Moen" wrote: I have a program that I can presently only run using the command line window (which used to be the MS-DOS window I guess). I would like to integrate this program with programs I've written in VBA. Is it possible to call "DOS" programs using VBA code? Help would be greatly appreciated. Cheers, Thomas |
running command line programs from Excel
I think the code you want is
Shell Environ("comspec") but read the help file first :) hth Keith |
running command line programs from Excel
Sub runbat()
Call Shell(Environ$("COMSPEC") & " /c c:\mybat.bat", vbNormalFocus) End Sub |
how to get the return value?
I am trying to use redirection and it does not work.
*********** ds = InputBox("Type in reporting date as YYYY-MM-DD", "reporting date") exestr = "Rterm --restore --save < m.in.R out.txt --args " & ds ret = Shell(exestr) ' opens Rterm and does not source the script ************* if I put the string in a batch file aaa.bat and use ret=Shell(aaa.bat) then redirection works, but I lose the return value from the process. ret simply reports whether cmd started successfully. I need to have the value returned from Rterm, which is 0 upon successful finish and -1 otherwise. Thank you all "teepee" wrote: Sub runbat() Call Shell(Environ$("COMSPEC") & " /c c:\mybat.bat", vbNormalFocus) End Sub |
how to get the return value?
Redirection, like non-built-in DOS function calls, need to call the command processor in order to work. Try this Shell statement instead and see if it works...
ret = Shell(Environ$("comspec") & " /c " & exestr) Rick "stephen" wrote in message ... I am trying to use redirection and it does not work. *********** ds = InputBox("Type in reporting date as YYYY-MM-DD", "reporting date") exestr = "Rterm --restore --save < m.in.R out.txt --args " & ds ret = Shell(exestr) ' opens Rterm and does not source the script ************* if I put the string in a batch file aaa.bat and use ret=Shell(aaa.bat) then redirection works, but I lose the return value from the process. ret simply reports whether cmd started successfully. I need to have the value returned from Rterm, which is 0 upon successful finish and -1 otherwise. Thank you all "teepee" wrote: Sub runbat() Call Shell(Environ$("COMSPEC") & " /c c:\mybat.bat", vbNormalFocus) End Sub |
All times are GMT +1. The time now is 05:18 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com