Microsoft Office Tutorials and References
In Depth Information
16.1.4.2 OnTime method
Left Arrow
{LEFT}
Num Lock
{NUMLOCK}
Page Down
{PGDN}
Page Up
{PGUP}
Return
{RETURN}
Right Arrow
{RIGHT}
Scroll Lock
{SCROLLLOCK}
Tab
{TAB}
Up Arrow
{UP}
F1 through F15
{F1} through {F15}
To combine keys with Shift, Ctrl, or Alt, use the following prefixes:
Shift
+ (plus sign)
Ctrl
^ (caret)
Alt
% (percent sign)
For instance, to denote the Alt-F2 key combination, write "%{F2}". To denote Ctrl-Shift-Enter,
write "^+{ENTER}".
In order to use one of the characters +, ^, %, {, }, or ~ without having it interpreted as a special
key, simply enclose the character in braces. For instance, to reassign the { key, we would assign
the Key parameter to "{{}".
16.1.4.2 OnTime method
This method is used to run a procedure at a specific time or after a specific amount of time has
passed. The syntax is:
Application.OnTime( EarliestTime , Procedure , LatestTime , Schedule )
Of course, the Procedure parameter is the name of the macro to run. The EarliestTime
parameter is the time you want the macro to be run. To specify a time, we use the TimeValue
function. For instance, the following code executes the macro test in the ThisWorkbook code
module of the book1 workbook at 3:58 P.M.:
Application.OnTime TimeValue("3:58 PM"), _
"d:\excel\book1.xls!ThisWorkbook.test"
LatestTime is an optional parameter that specifies the latest time at which the procedure can
begin running. We can use the TimeValue function to specify a time for this parameter, or we
can set LatestTime to EarliestTime plus some additional time. For instance, the following
code requires that Excel run the macro no later than 30 seconds following 3:58 P.M.:
Application.OnTime TimeValue("3:58 PM"), _
"d:\excel\book1.xls!ThisWorkbook.test", _
TimeValue("3:58 PM") + 30
The LatestTime parameter may be useful, since if Excel is busy (running another procedure, for
instance), then execution of the macro denoted by Procedure will be delayed. If you do not
want the macro to be run after a certain time, then set the LatestTime parameter.
Search JabSto ::

Custom Search