Microsoft KB Archive/59432

{|
 * width="100%"|

Problems Using SEND.KEYS Function in Excel

 * }

-

The information in this article applies to:


 * Microsoft Excel for Windows, versions 2.x, 3.0, 4.0, 5.0
 * Microsoft Excel for OS/2, versions 2.2 and 3.0

-

SUMMARY
In some situations, the Microsoft Excel SEND.KEYS function may not work as desired. For example, if you have several sequences of keys that you would like to send to Microsoft Excel, and each must be completed before the next can be sent, SEND.KEYS may not work as anticipated.

This problem occurs because of the way Microsoft Excel processes the SEND.KEYS function. When Microsoft Excel is the active application, the wait_log is assumed to be FALSE, even if you set it to TRUE.

Workaround
To work around this problem, you must temporarily halt the macro to process the keys and resume at the next line after an appropriate time delay.

MORE INFORMATION
When this situation occurs, use the ON.TIME function in conjunction with the HALT function to force Microsoft Excel to process each text string before moving on to the next. For example, if String1 must be processed before String2, use the following format:

  A1:  Macro1 A2: =SEND.KEYS(String1) A3: =ON.TIME(NOW+0.000001,&quot;Macro1.xlm!R5C1&quot;) A4: =HALT A5: =SEND.KEYS(String2) A6: =RETURN

In the above example, the ON.TIME function tells Microsoft Excel to wait for about one second and then resume execution at the point designated (Macro1.xlm!R5C1). The effect is that the macro temporarily halts, allowing the first sequence of keys sent to Microsoft Excel to be processed. After allowing Microsoft Excel enough time to process those keys (in this case, one second), the macro starts back up at the point designated and sends the second string.

Note: the information above also applies to version 5.0 only when using version 4.0 macro language.