Running batch file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there, have a batch file I have created that when I open through Windows
Explorer, it will launch a programme and write the export files.
How can I get this batch file to run as part of a macro to automate the
batch process, have tried loads of ways, but no joy.

Thanks
 
Hi there, have a batch file I have created that when I open through Windows
Explorer, it will launch a programme and write the export files.
How can I get this batch file to run as part of a macro to automate the
batch process, have tried loads of ways, but no joy.

Try this:
Shell (Environ("COMSPEC") & " /c ""yourbatch.cmd""")

This will run the batch file asynchronously. If your code has to wait
until the batch file is finished *and* runs under Win16 (unlikely as
that may be), see <http://support.microsoft.com/?kbid=99940>. For one
way of doing the same thing under Win32, see
<http://newmanservices.com/vbsource/shellmodal.htm>.

On the other hand, you may be able to poll for the existence of some
semaphore file to continue your code. E.g. your code deletes the
file DONE.TXT and your batch file creates when it's finished. Then:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
...
With CreateObject("Scripting.FileSystemObject")
If .FileExists("d:\dir\DONE.TXT") Then .DeleteFile ("d:\dir\DONE.TXT")
Shell (Environ("COMSPEC") & " /c ""yourbatch.cmd""")
Do Until .FileExists("d:\dir\DONE.TXT")
DoEvents
Sleep 1000
Loop
End With
 
Back
Top