XL: SendKeys Method Runs Before Built-In SendKeys Statement

Last reviewed: September 2, 1997
Article ID: Q110891
The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel 97 for Windows

SYMPTOMS

In Microsoft Excel, if you use both the SendKeys statement and the Application.SendKeys method in a Visual Basic procedure, the order in which the keystrokes run may be different than the order of the keystroke commands in your procedure.

CAUSE

In a Visual Basic procedure, the Application.SendKeys method is run before the SendKeys statement.

WORKAROUND

To ensure that the keystrokes you send using SendKeys in a Visual Basic procedure run in the correct order, do one of the following:

  • Use either the Application.SendKeys method or the built-in SendKeys statement, but not both in the same procedure.

    -or-

  • Use the Wait argument with both the SendKeys commands. When you use the Wait argument, all the keys in the SendKeys command run before the next line in the procedure runs. The following is an example of using the wait argument with the built-in SendKeys statement:

          SendKeys "{enter}", True
    

    The following is an example of using the Wait argument with the SendKeys method:

          Application.SendKeys "{enter}", True
    

MORE INFORMATION

The SendKeys command is available both as a built-in Visual Basic statement, and as a method of the Microsoft Excel Application object. You can use either SendKeys command to send keystrokes to the active window. This command is useful when you want to send commands to another application that does not support linking, embedding, OLE Automation, or dynamic data exchange (DDE). The two commands provide the same general functionality, one exception being the order in which they are run when used in the same procedure as described above.

REFERENCES

"Visual Basic User's Guide," version 5.0, pages 214-215

For more information about the SendKeys Method or the SendKeys Statement, click the Search button in the Visual Basic Reference and type:

    SendKeys


Additional query words: 5.00 7.00 8.00 97
Keywords : kbprg PgmOthr
Version : 5.00 5.00c 7.00 7.00a 97
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.