View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Launch a .bat file with VBA

It depends on how you define getting the results

Once the shell command is executed, the vba code continues on. The bat file
is running in another thread disconnected from the vba code. What are you
trying to accomplish and how are you trying to use the results of the bat
file.

--
Regards,
Tom Ogilvy


" wrote:

Thanks Tom. That seems to run the batch file, but the results of the
batch file don't seem to be happening. I looked up the shell command in
the help file and saw the following note:

Note By default, the Shell function runs other programs
asynchronously. This means that a program started with Shell might not
finish executing before the statements following the Shell function are
executed.

Do you think it's possible that I am not getting my results because the
MS-DOS command prompt window is being closed before it's finished
executing the batch file?

Thanks.

Tom Ogilvy wrote:
I am sure that works, but this worked fine for me as well:

Sub EFG()
Shell "C:\Data2\mybat.bat"
End Sub

--
Regards,
Tom Ogilvy



"Gary''s Student" wrote:

For example:

Sub belfry()
x = Shell("cmd.exe /c C:\x.bat", 1)
End Sub


CMD "understands" what to do with .bat files
--
Gary's Student


" wrote:

Is there a way to launch a .bat file in VBA? I have read to use the
shell command to launch programs, but that doesn't seem to be working
so I'm not sure that it works for anything other than executables? Is
there any way to do this? Thanks much!

Nick