Problems Using SEND.KEYS Function in Excel

ID: Q59432


The information in this article applies to:


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,"Macro1.xlm!R5C1")
   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.


REFERENCES

"Function Reference," version 3.0, page 168
"Functions and Macros," version 2.x, page 354

Additional query words: 2.0 2.00 2.01 2.1 2.10 2.2 2.20 2.21 3.0 4.0 4.0a 4.00a


Keywords          : 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: March 16, 1999