VBA Couldnot run bat file RRS feed

  • Question

  • Hi All,

    I developed an Excel vba macro to run a MS-DOS batch file (Copies files from one location to other location). Here is the code snippet.



    Set objWSH = CreateObject("WScript.Shell")

    lngErrorCode = objWSH.Run(TCfccBatchCmd, WindowStyle:=0)


    When I run the macro, the excel application is closing without any error message. It is running fine in some machines.

    The excel application is closing when I run any .bat file.  I tried to run the .bat file in many ways like using shell.exec and Shell(“ ”).

    If anyone knows the solution or root cause, please let me know.


    Thanks in Advance!


    Thank you!

    Best Regards,


    Thursday, September 14, 2017 1:51 PM

All replies

  • What happens if you make it a Powershell script?

    Sub Test()
      Dim retval As Variant
      Dim psCmd As String
      psCmd = "Powershell -noprofile -ExecutionPolicy RemoteSigned &'C:\temp\copy.ps1'"
      Debug.Print psCmd
      retval = Shell(psCmd, vbNormalFocus)
    End Sub


    Copy-Item -Path 'C:\temp\iso\*.img' -Destination 'C:\temp\iso2\' -recurse -Force -Verbose

    • Edited by mogulman52 Friday, September 15, 2017 1:50 PM
    Thursday, September 14, 2017 10:54 PM