Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Halting Prematurely

Status
Not open for further replies.

Boanerge

Technical User
Jul 24, 2007
3
US
I have a long running vba process (4-8 hours) that will sometimes halt prematurely. Basically, the vba code opens an external process and then waits for that process to change a file. Once that file changes it loops and runs the process again. It has to do this about 5000 times. I will occasionally go in and find that the external process it runs is sitting there completed but the vba code has stopped checking to see if it has finished. So, I pause the vba code and it highlights the DoEvents statement in the middle of the loop that checks for the process' completion. When I hit F8 to go to the next statement it starts the code over at the beginning of the procedure. Has anyone seen this behavior before? Any guesses to what is causing it?

Thanks.
 
Okay, I was trying to think through every possibility for this code and it hit me what was happening. I was using Timer to pause the function and since this uses the number of seconds since midnight the function was choking as it crossed over midnight. Hopefully this will help anybody else who might make this mistake.
 
Assuming you are opening this process with a shell command (I can't think of any other way to open an external proccess) you could also use OpenProcess, WaitForSingleObject, and CloseHandle methods in lib32 to wait for the process to complete as shown here:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top