Vba to wait until batchjob completed

dhen21dx

Board Regular
Joined
May 10, 2013
Messages
166
Hello,

I have a batch Job run via Access however i didn't know how to trigger access to wait until completed and move to next action.
Thanks
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Could you do it via a Macro?
Alternatively set a flag somewhere and clear it when batch job is complete, and check to see if it has been cleared from the calling process.?

Macro might be a cleaner option.?
 
Upvote 0
Could you do it via a Macro?
Alternatively set a flag somewhere and clear it when batch job is complete, and check to see if it has been cleared from the calling process.?

Macro might be a cleaner option.?
Hello,

if i will be using Macro, what specific action do i need to use, i just check on the list and cannot see any applicable to running batchjob.

Thanks
 
Upvote 0
I have a batch Job run via Access
What does that mean? A batch of what? Literal batch .bat files? Scripts? Queries? Provide some details. There are a number of options available, but I don't know enough about your process to offer much. :)
 
Upvote 0
What does that mean? A batch of what? Literal batch .bat files? Scripts? Queries? Provide some details. There are a number of options available, but I don't know enough about your process to offer much. :)
Yeah Literally Batch Job file, ".bat" to running once button clicked
 
Upvote 0
Ok. The easy enough way is to query running processes using WMI. I don't know if I have any ready example for batch files, but I imagine it will work. I'll see if I can adapt an example I recently posted to work with bat files. BRB.
 
Upvote 0
Hello,

if i will be using Macro, what specific action do i need to use, i just check on the list and cannot see any applicable to running batchjob.

Thanks
Well Macroes only run functions, but I was thinking of you running a particular function.
Now you have mentioned actual bat files, then I do not think that will work anyway.

I ran 'batch'jobs in one of my places of work, but they were access batch jobs, import, update, append etc.
 
Upvote 0
This works, though you might wish to add some pause and timeout code. Let me know if you need help cleaning it up.

VBA Code:
Option Explicit

Sub Example()
    Dim WMI As Object
  
    Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
  
    Shell "C:\Users\Tom\Desktop\test1.bat"
    WaitUntilNotRunning WMI, "test1.bat"

    Shell "C:\Users\Tom\Desktop\test2.bat"
    WaitUntilNotRunning WMI, "test2.bat"

    MsgBox "All Done"
End Sub

Sub WaitUntilNotRunning(WMI, CmdLineSearch)
    Do
        DoEvents
    Loop Until Not ItsRunning(WMI, CmdLineSearch)
End Sub

Function ItsRunning(WMI, CmdLineSearch) As Boolean
    Dim Processes, Process
     
    Set Processes = WMI.ExecQuery("select * from win32_process")
   
    For Each Process In Processes
        If InStr(Process.CommandLine, CmdLineSearch) Then
            ItsRunning = True
            Exit Function
        End If
    Next
End Function
 
Upvote 0

Forum statistics

Threads
1,221,531
Messages
6,160,361
Members
451,642
Latest member
mirofa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top