Collect answer .bat from VBA


Des of VBA I execute a bat using Call Shell (...) and it works correctly.

Now I need to pick up the answer of this bat, which has an "Echo answer".

Any ideas on how to do this?

Thank you,

asked by David_helo 10.08.2018 в 10:26

1 answer


I have answered in SO in English. Answer Here

I enclose a translation.

You can not return a response using Call Shell . You need to use WScript.Shell .

Dim sh As Object
Set sh = CreateObject("WScript.Shell")
Dim ex As Object
Set ex = sh.Exec("C:\Directorio\A\Archivo.bat")
Dim ans As String
ans = ex.StdOut.ReadAll

In a more summarized way, if you want to save lines:

Dim ans As String
ans = CreateObject("WScript.Shell").Exec("C:\Directorio\A\Archivo.bat").StdOut.ReadAll
answered by 13.08.2018 / 08:18