Applies To
Application Object.
Description
Sends keystrokes to the active application. This method is not available on the Apple Macintosh.
Syntax
object.SendKeys(keys, wait)
object
Optional. The Application object.
keys
Required. The key or key combination you want to send to the application, as text.
wait
Optional. If True, Microsoft Excel waits for the keys to be processed before returning control to the macro. If False or omitted, the macro continues to run without waiting for the keys to be processed.
Remarks
This method places keystrokes into a key buffer. In some cases, you must call this method before you call the method that will use the keystrokes. For example, to send a password to a dialog box, you must call the SendKeys method before you display the dialog box.
The keys argument can specify any single key, or any key combined with ALT, CTRL, or SHIFT, or any combination of those keys. Each key is represented by one or more characters, such as "a" for the character a, or "{ENTER}" for the ENTER key.
To specify characters that aren't displayed when you press the key, such as ENTER or TAB, use the codes shown in the following table. Each code in the table represents one key on the keyboard.
Key |
Code |
BACKSPACE |
"{BACKSPACE}" or "{BS}" |
BREAK |
"{BREAK}" |
CAPS LOCK |
"{CAPSLOCK}" |
CLEAR |
"{CLEAR}" |
DELETE or DEL |
"{DELETE}" or "{DEL}" |
DOWN ARROW |
" |
END |
"{END}" |
ENTER (numeric keypad) |
"{ENTER}" |
ENTER |
"~" (tilde) |
ESC |
"{ESCAPE} or {ESC}" |
HELP |
"{HELP}" |
HOME |
"{HOME}" |
INS |
"{INSERT}" |
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}" |
You can also specify keys combined with SHIFT and/or CTRL and/or ALT. To specify a key combined with another key or keys, use the following table.
To combine with |
Precede the key code by |
SHIFT |
"+" (plus sign) |
CTRL |
"^" (caret) |
ALT |
"%" (percent sign) |
Example
This example uses the SendKeys method to quit Microsoft Excel for Windows.
Application.SendKeys("%fx")