stop VBA execution while in external application
stop VBA execution while in external application
(OP)
I am running a small VBA program which at some point may call in an external exe program, then returns to VBA. The problem I have is it does not return to the point where the exe program was called. It keeps running to the end, in parallel. How do I stop it while running the exe to return in the same point?






RE: stop VBA execution while in external application
1. Guess an amount of time that the exe will take (I'm assuming no user interaction with the exe), add a safety factor, and use a the Timer function and a DoEvents inside a While loop to pause the macro execution.
2. Have your VBA code somehow check for the results of the exe program within a loop containing a DoEvents statement. Depending on what these results are, code to check for results may be processor intensive.
3. Have your VBA code check the running processes and see if your exe is running. Once again, the loop needs to contain DoEvents. There are plenty of places to get sample code to check for running processes. Here's one I found. Never used any of the code though. http://www.vbforums.com/showthread.php?p=2748682
-handleman, CSWP (The new, easy test)
RE: stop VBA execution while in external application
RE: stop VBA execution while in external application
I think that's the problem. The VBA app doesn't know whether the exe is done or not, and does not pass a result to the VBA. For example, maybe he's trying to automate opening a model, allowing the user to change custom properties using PropaGator or the like, then save as PDF. There would be no way for the VBA macro to know that the user was finished with PropaGator without looking for the PropaGator process.
-handleman, CSWP (The new, easy test)
RE: stop VBA execution while in external application
RE: stop VBA execution while in external application
-handleman, CSWP (The new, easy test)
RE: stop VBA execution while in external application
Wait loops in VBA are a pain because they consume processor power without doing much when done poorly.
RE: stop VBA execution while in external application
So there is user interaction with the external program. It can't be timed. I looked at the link in option 3 and got scared.
RE: stop VBA execution while in external application
-handleman, CSWP (The new, easy test)
RE: stop VBA execution while in external application
Since you are only dealing with custom properties and maybe need to make a form, perhaps just code the custom property entries into your VBA app?
RE: stop VBA execution while in external application
-handleman, CSWP (The new, easy test)
RE: stop VBA execution while in external application
Now, going back to the option 3. I got those functions from there and into my application. How do I use them? Within a Do While loop?
RE: stop VBA execution while in external application
RE: stop VBA execution while in external application
MsgBox "Do not click OK until you have entered laser program!"
If you really want to make sure the user goes to the exe's window, use AppActivate to bring it to the front prior to the MsgBox.
Of course, whether you use a modal form or just a MsgBox, your code will have to trap for the possibility of the user not following instructions and clicking "OK" too soon.
-handleman, CSWP (The new, easy test)
RE: stop VBA execution while in external application
CODE
Set exec = CreateObject("WScript.Shell").exec("notepad")
Do While exec.Status = 0
Sleep 100
Loop
CODE
Eric
RE: stop VBA execution while in external application
-handleman, CSWP (The new, easy test)
RE: stop VBA execution while in external application
RE: stop VBA execution while in external application
-handleman, CSWP (The new, easy test)
RE: stop VBA execution while in external application
Eric
RE: stop VBA execution while in external application
I will create a small form inside the macro where the user can enter the missing information instead of runnin an external application.
Thank you guys for your support. Stars for you.