In my VBA code I call the bat using Call Shell(....).
I need now to get the "Echo answer" inside the batch-file in VBA.
How can I do that?
My batch-file:
@echo off
IF exist %3 (robocopy %1 %2 /e ) ELSE (echo 1)
I want to get that "1" in VBA.
In my VBA code I call the bat using Call Shell(....).
I need now to get the "Echo answer" inside the batch-file in VBA.
How can I do that?
My batch-file:
@echo off
IF exist %3 (robocopy %1 %2 /e ) ELSE (echo 1)
I want to get that "1" in VBA.
You can't return answers using Call Shell. You need to use WScript.Shell, and can use the read lines from the execution object it returns.
Dim sh As Object
Set sh = CreateObject("WScript.Shell")
Dim ex As Object
Set ex = sh.Exec("C:\Path\To\File.bat")
Dim ans As String
ans = ex.StdOut.ReadAll
A shorthand, if you want to save lines:
Dim ans As String
ans = CreateObject("WScript.Shell").Exec("C:\Path\To\File.bat").StdOut.ReadAll