Solved I'd like to close a batch file from VBA code in excel 2007

May 3, 2013 at 12:27:15
Specs: Windows 7
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 :)


See More: Id like to close a batch file from VBA code in excel 2007

Report •


#1
May 3, 2013 at 13:20:06
✔ Best Answer
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.

Law of Logical Argument: Anything is possible if you don't know what you're talking about.


Report •

#2
May 3, 2013 at 13:57:45
Newbie10... First, thanks for such a speedy reply. Secondly, your code worked brilliantly. Thank you so much :)

Report •

#3
May 3, 2013 at 14:02:35
Glad I can help!!

Don't forget to mark the best answer so others who have similar problems know that this thread is solved!

Law of Logical Argument: Anything is possible if you don't know what you're talking about.


Report •

Related Solutions

#4
May 3, 2013 at 14:07:41
Alternatively, just add this to the start of the line that launches excel:
start ""

Also, never call exit from a batch script. If the user launched the script from explorer, it's completely redundant. If the user launched the script from the Command Prompt, you're closing the window on him, and that's rude.

How To Ask Questions The Smart Way


Report •

#5
May 3, 2013 at 14:14:28
Thanks for the advice Razor. I've created desktop icon to begin the launch sequence but I can also see how I can use your suggestion in other instances. Many thanks :)

Report •


Ask Question