2012-11-08 31 views
0

我有一個運行命令提示符(如果可執行文件可用)的宏。在檢查可用可執行文件之前,宏等待5分鐘。問題是這個鎖定excel。我更願意做的是將控制權交還給用戶五分鐘。將控制權傳遞給用戶指定的時間量

這就是現在的代碼片段。

Do Until TuflowEx < Range("Exe").Value ' Check if number of executables running is less than the user specified maximum 
    Application.Wait (Now + TimeValue("0:05:00")) ' Wait 5 minutes before checking again 
    TuflowEx = TuEx() ' Run TuEx to get the currently active number of executables 
Loop 

乾杯

回答

1

使用Application.Ontime代替。

只需創建一個例程來執行檢查,並在檢查成功時讓它恢復邏輯。

Sub ChecktuflowEx() 
    If TuEx() => Range("Exe").Value Then 
     'whatever you want 
    Else 
     'Check again in 5 minutes. 
     Application.OnTime Now + TimeValue("0:05:00"), "ChecktuflowEx" 
    End If 
End Sub 
+0

正是我所需要的。謝謝! – user1650538