Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default running command line programs from Excel

I think the code you want is

Shell Environ("comspec")

but read the help file first :)

hth

Keith

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default running command line programs from Excel

Sub runbat()

Call Shell(Environ$("COMSPEC") & " /c c:\mybat.bat", vbNormalFocus)

End Sub




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default 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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Programs running slow Omaha Tony Excel Discussion (Misc queries) 0 March 7th 10 03:47 PM
Running Macros from Command line DrukeEr Excel Programming 3 July 26th 05 06:03 PM
Running a macro from a command line Kelly Excel Programming 4 November 30th 04 08:17 PM
Running a macro from the command line Czech Excel Programming 1 October 28th 04 09:51 PM
Running external programs Alan Beban[_4_] Excel Programming 4 December 20th 03 03:06 PM


All times are GMT +1. The time now is 10:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"