Page 116 - Open Soource Technologies 304.indd
P. 116
Event Driven Programming
While intID < 1 Or intID > 3
intID = InputBox(“Enter employee’s ID”)
Wend
MsgBox “Employee name = “ & Choose(intID, “Bob”, “Denise”, “Ted”)
5.2.10 Sending Keystrokes to Other Programs
It is time to print out the 349 screen spreadsheets you have created in your new spreadsheet
program to show the boss. Regrettably, there just doesn’t seem to be any way to print them out
except one at a time, using the File menus Print item. Can Visual Basic help here?
Yes. You can use the SendKeys() function to send keys to the program that currently has the
Windows focus, just as if you typed in those keys yourself. Using the Alt key, you can reach the
menu items in your spreadsheet_s File menu. The day is saved, because now you can automate
your printing job, even waiting until the spreadsheet program processes the current keystroke
before continuing. Here is how you use SendKeys():
SendKeys string [, wait]
The string expression is the string you want to send to the other program. The wait argument is a
Boolean value indicating the wait mode. If False (which is the default), control returns right after the
keys are sent. If True, the keystrokes must be processed by the other program before control returns.
If the keys you want to send are not simple text, just embed the codes, in the text you send to
SendKeys().
Send Keys ()
Key Codes,
Key Code
Backspace {BACKSPACE}. {BS}. or {BKSP}
Break {BREAK}
Caps Lock {CAPSLOCK}
Del or Delete {DELETE} or {DEL}
Dowen arrow {DOWN}
End {END}
Enter or {ENTER} or
Return
Esc {ESC}
Help {HELP}
Home {HOME}
Ins or Insert {INSERT} or {INS}
Left arrow {LEFT}
110 LOVELY PROFESSIONAL UNIVERSITY