단, 이 경우 등록된 타이머를 취소하는 방법에 유의. 기존에 등록된 타이머가 남아있으면 엑셀이 재 시작된다.
자세한 사용 예제 참조: http://www.cpearson.com/excel/OnTime.aspx
Application.OnTime Method
Schedules a procedure to be run at a specified time in the future (either at a specific time of day or after a specific amount of time has passed).
Syntax
expression.OnTime(EarliestTime, Procedure, LatestTime, Schedule)
expression A variable that represents an Application object.
Parameters
Name |
Required/Optional |
Data Type |
Description |
EarliestTime |
Required |
Variant |
The time when you want this procedure to be run. |
Procedure |
Required |
String |
The name of the procedure to be run. |
LatestTime |
Optional |
Variant |
The latest time at which the procedure can be run. For example, if LatestTime is set to EarliestTime + 30 and Microsoft Excel is not in Ready, Copy, Cut, or Find mode at EarliestTime because another procedure is running, Microsoft Excel will wait 30 seconds for the first procedure to complete. If Microsoft Excel is not in Ready mode within 30 seconds, the procedure won’t be run. If this argument is omitted, Microsoft Excel will wait until the procedure can be run. |
Schedule |
Optional |
Variant |
True to schedule a new OnTime procedure. False to clear a previously set procedure. The default value is True. |
Remarks
Use Now + TimeValue(time) to schedule something to be run when a specific amount of time (counting from now) has elapsed. Use TimeValue(time) to schedule something to be run a specific time.
Example
This example runs my_Procedure 15 seconds from now.
Visual Basic for Applications |
Application.OnTime Now + TimeValue("00:00:15"), "my_Procedure" |
This example runs my_Procedure at 5 P.M.
Visual Basic for Applications |
Application.OnTime TimeValue("17:00:00"), "my_Procedure" |
This example cancels the OnTime setting from the previous example.
Visual Basic for Applications |
Application.OnTime EarliestTime:=TimeValue("17:00:00"), _ |
'공부 > VBA' 카테고리의 다른 글
VBA - Early Binding vs. Late Binding (0) | 2011.08.09 |
---|---|
VBA - format 함수 사용법 (0) | 2011.04.19 |
VBA - Me keyword (0) | 2011.04.18 |