View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Mr BT[_2_] Mr BT[_2_] is offline
external usenet poster
 
Posts: 20
Default Executing a bat file from Excel

empty echos?
Could you explain how I could include this in the vb script?

Thanks

MrBT
"Harlan Grove" wrote in message
ps.com...
Gary''s Student wrote...
I don't know.....maybe a pair of empty echos???

...

Yup.

"Mr BT" wrote:

...
I forgot to mention, in order for this to work the way I need it
to, I need, I guess, a sendkeys command for the batch file to hit
ENTER twice before it closes.


Macro could be

Sub foo()
Dim x As Variant
x = Shell(Environ("COMSPEC") & _
" /c (echo/&echo/) | ""x:\what\ever.bat""")
End Sub

Peruse the Google Groups archive for the alt.msdos.batch.nt newsgroup
if curious why this particular form for echo is optimal.

Also, FWIW, no exit statement is necessary in the batch file. The
console window will close when the batch file ends. You only need
explicit exit commands when exiting before reaching the end of the
batch file.

Also note that batch files launched this way will run asynchronously,
i.e., the Excel macro that launches it won't wait for the batch file
to end before it continues past the Shell call.