SendKeys Statement

Named Arguments

Yes

Syntax

SendKeys string[, wait]

string

Use: Required

Data Type: String

The keystrokes to send.

wait

Use: Optional

Data Type: Boolean

Expression evaluating to True or False denoting the wait mode.

Description

Programmatically simulates specified keys being typed at the keyboard.

Rules at a Glance

  • SendKeys sends its keystrokes to the application and application window that has the focus.

  • One or more characters represent each key.

  • The default setting for wait is False. Setting wait to True informs the application to wait until the keystrokes have been processed before passing control back to the current procedure. A False setting returns control back to the current procedure as soon as the keys are sent.

  • To send normal alphabetical or numeric characters, simply use the character or characters enclosed in quotation marks. For example, "SOME Text 123".

  • The following characters represent special keys or have special meaning within the SendKeys string:

    Character Special Key Representation
    + Shift
    ^ Ctrl
    % Alt
    ~ Enter
    [ ] May be used by Dynamic Data Exchange (DDE)

    To use these characters literally, you must surround the character with braces. For example, to specify the percentage key, use {%}.

  • Preceding a string with the special characters described in the table above allows you to send a keystroke combination beginning with Shift, Ctrl, or Alt. For example, to specify Ctrl followed by M, use ^M.

  • If you need to specify that the Shift, Ctrl, or Alt ...

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.