Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file completion  (Read 3327 times)

0 Members and 1 Guest are viewing this topic.

faulkem

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Unknown
    Batch file completion
    « on: October 22, 2010, 03:49:02 AM »
    Hello

    OS: Windows XP
    App: Access 2003 SP3

    I am running a Batch file in VBA (see code below). I want to ensure the Batch file completes it's work (creating a TXT file) before moving onto the
    next line of VBA. I currently Loop 20 million times before moving to the next line of VBA. This is a workaround... I'm looking for a solution.

    VBA....
      'Run external Batch file to collect documents
      Shell ("c:\BatchFile.bat"), vbMinimizedNoFocus
      'Pause VBA until Batchfile completed!
    VBA....

    Any help would be gratefully appreciated.

    Regards
    Mike

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Batch file completion
    « Reply #1 on: October 22, 2010, 07:04:40 AM »
    There are a couple of ways to do this. This link describes one of them. I would suggest you run the shellandwait function in a loop until you receive a success return code.

    Another possibility is to create a Windows Shell object in your code and use the run method to execute your batch file. Unlike the VBA shell command, the run method has a wait on return parameter you can set to true.

    Good luck.  8)
    « Last Edit: October 22, 2010, 07:45:06 AM by Sidewinder »
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    faulkem

      Topic Starter


      Newbie

      • Experience: Beginner
      • OS: Unknown
      Re: Batch file completion
      « Reply #2 on: October 23, 2010, 06:46:11 AM »
      Many thanks... ShellAndWait works just perfect!