Controlling Another Application

Now that you know how to use VBA statements to start a program and switch between applications, let's see how one application can communicate with another. The simplest way for an application to get control of another is by means of the SendKeys statement. This statement allows you to send a series of keystrokes to the active application window. You can send a key or a combination of keys and achieve the same result as if you worked directly in the active application window using the keyboard. The SendKeys statement looks as follows:

SendKeys string [, wait]

The required argument string is the key or key combination that you want to send to the active application. For example, to send a letter "f," use the following instruction:

SendKeys "f"

To send the key combination Alt+f, use:

SendKeys "%f"

The percent sign (%) is the string used for the Alt key.

To send a combination of keys, such as Shift+Tab, use the following statement:

SendKeys "+{TAB}"

The plus sign (+) denotes the Shift key. To send other keys and combinations of keys, see the corresponding strings listed in Table 9-3.

Was this article helpful?

0 0

Post a comment