Re: Launch a .bat file with VBA

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Maybe when you run the .bat, it expects the files that it works on to be in the
same folder.

Maybe, you can add commands to go to that drive and folder to the top of the
..bat file:

@echo off
c:
cd C:\yourfolderhere
....

=====
Or maybe the .bat file isn't finishing quickly enough. You could use a method
to wait for the .bat file to finish--or you could just estimate how long it
takes and pause your macro a bit.

'shell to the .bat file
application.wait now+timeserial(0,0,10)
'(for 10 seconds)





Nick.Korynski@xxxxxxxxx wrote:

The bat file takes a grouping of binary files in a folder and combines
them then deletes the original binary files. When I run the bat file
just by double clicking it in the folder, it works fine, but when I try
to run it through my VBA code, I see the MS-DOS windown come up and it
looks like it runs fine, but then the old binary files are there
untouched.

Tom Ogilvy wrote:
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


"Nick.Korynski@xxxxxxxxx" 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


"Nick.Korynski@xxxxxxxxx" 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





--

Dave Peterson
.



Relevant Pages

  • Re: What is the difference between CMD and BAT file ?
    ... BAT will not cause error message for commands like ... NOT be listed under non NT i.e. Windows 9x, Me, etc. ... typed in a Command Prompt or the Run command. ... File Extension .cmd ...
    (microsoft.public.windowsxp.general)
  • Re: .Bat files
    ... and specifically at the section on the command "chmod" gives them the ... and the example command I gave ... above would try to make all files that end with ".bat" [in your current ... think a good book on shell "scripting" would go a lot further than the man ...
    (alt.os.linux.suse)
  • Re: How to run a batch file or VBS from Access VBA code?
    ... IIRC to run a .bat or .cmd file you must invoke the Windows command ... >>>Even reproducing the functionality of the batch files may be possible in VBA. ... >I inherited a series of old ftp bat files, but I find it cubersome to use ...
    (microsoft.public.access.modulesdaovba)
  • Re: using START to try and parallelize copy operations, getting hu
    ... Nothing in the bat to be executed comes out, ... nothing after the first start command. ... @echo off ... I have a batch file I'm launching from a web page using psexec.exe. ...
    (microsoft.public.windows.server.scripting)
  • Re: [PHP] shell_exec, batch files, and IIS on Windows
    ... I can't execute .bat ... my development workstation (XP running Apache). ... command through cmd.exe on the server, but some of the commands in the ... I suspect that IIS is a key culprit, ...
    (php.general)