# Excel VBA Shell and Wait



## jgspencer (Apr 10, 2009)

I need help with some code regarding shell and wait. I am trying to write a shell that triggers a .exe file and regrinds hours in the POS system that my restaurants use. I need to have the startdate equal the cell in Sheet 1 Cell A1 and then go back to Monday and stop before Sunday. A few things I am having trouble with:

-How do I set the startdate to equal that cell and format the start date to "yyyyddmm" and run the .exe file to loop from startdate to Monday and stop before Sunday.
-If the file does not exist, how do I handle the error so the loop continues.
-Also, I need it to also incorporate a shell and wait that will not continue to the next step of code until the shell has finished but to stop running after 3 minutes if the shell does not complete the task.

I have read about the shell and wait function but I don't really understand it that much. Here is what I have so far even though it's not much:

Sub GndHours()

On Error GoTo GndErr

Dim RetVal
RetVal = Shell("C:\aloha\bin\grind.exe /date yyyyddmm")

ExitHere:
Exit Sub

GndErr:
Select Case Err.Number
Case Else
Resume ExitHere
End Select
End Sub

Your help will be much appreciated.


----------

