PDA

View Full Version : vba to automatically hit a key on the keyboard



chungtinhlak
09-17-2009, 03:53 PM
Is there a way to set the return key (enter) on the keyboard to hit automatically at a certain point in your macro?

I tried

VBA.KeyCodeConstants.vbKeyReturn = true but it gave me an error of invalid used of property, please help.

nst1107
09-17-2009, 03:57 PM
Try SendKeys "~"

chungtinhlak
09-17-2009, 03:59 PM
can you expand on that a little? thanks

nst1107
09-17-2009, 04:04 PM
Copied from Excel Help:


SendKeys Statement
Sends one or more keystrokes to the active window as if typed at the keyboard.
Syntax
SendKeys string[, wait]
The SendKeys statement syntax has these named arguments (http://www.vbaexpress.com/forum/ms-help://MS.EXCEL.DEV.12.1033/EXCEL.DEV/content/HV01200929.htm):
PartDescriptionstringRequired. String expression (http://www.vbaexpress.com/forum/ms-help://MS.EXCEL.DEV.12.1033/EXCEL.DEV/content/HV01200929.htm) specifying the keystrokes to send.WaitOptional. Boolean (http://www.vbaexpress.com/forum/ms-help://MS.EXCEL.DEV.12.1033/EXCEL.DEV/content/HV01200929.htm) value specifying the wait mode. If False (default), control is returned to the procedure (http://www.vbaexpress.com/forum/ms-help://MS.EXCEL.DEV.12.1033/EXCEL.DEV/content/HV01200929.htm) immediately after the keys are sent. If True, keystrokes must be processed before control is returned to the procedure.
Remarks

Each key is represented by one or more characters. To specify a single keyboard character, use the character itself. For example, to represent the letter A, use "A"
for string. To represent more than one character, append each additional character to the one preceding it. To represent the letters A, B, and C, use
"ABC"
for string.


The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses ( ) have special meanings to SendKeys. To specify one of these characters, enclose it within braces ( {}
). For example, to specify the plus sign, use
{+}
. Brackets ([ ]) have no special meaning to SendKeys, but you must enclose them in braces. In other applications, brackets do have a special meaning that may be significant when dynamic data exchange (http://www.vbaexpress.com/forum/ms-help://MS.EXCEL.DEV.12.1033/EXCEL.DEV/content/HV01200929.htm) (DDE) occurs. To specify brace characters, use
{{}
and
{}}
.