Computing Staff
  • 14

I’d Like To Close A Batch File From VBA Code In Excel 2007

  • 14

I’ve written a simple batch file which connects my pc to a server, configures and copies files to the local machine and then launches an excel 2007 application.

The batch file line to terminate itself (Exit) is not triggered until the excel app is closed. Is there a VBA command which will close the batch file?

Thanks in anticipation 🙂

Share

1 Answer

  1. I don’t think what you want is possible because as long as the prgram that the batch file opened is still open, that batch file is still technically running…
    However, you could use a VBScript to open the batchfile invisibly.

    Copy the following lines to a new notepad and save it with the file extention .vbs. You will need to change the path to your batch file.

    Set WshShell = CreateObject(“WScript.Shell”)
    WshShell.Run chr(34) & “C:\Batch Files\syncfiles.bat” & Chr(34), 0
    Set WshShell = Nothing
    I’ve tested this on my machine and it does what you are requesting.

    • 0