Link to home
Start Free TrialLog in
Avatar of satmisha
satmishaFlag for India

asked on

Why use of Application.SendKeys is not good coding practice in VBA, excel 2010

Hi Team,
I came to know the use of Application.SendKeys is not a good coding practice better to use windows API to achieve this functionality, I want to know why it is not good coding practice and its impact on the system. I appreciate if you could provide in support some link from microsoft/Authentic to justify the same.
Hopefully looking forward to hearing from you.
Regards,
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

SendKeys is the most crude way to communicate with other applications. The technique dates back to the first graphical user interface applications and before better ways of communicating between applications was developed. It's undependable and there are no ways to guarantee that the target objects are in place to receive the generated keystrokes.

The first better method to automate other applications was DDE or Dynamic Data Exchange:

http://en.wikipedia.org/wiki/Dynamic_Data_Exchange

These days it's much more common and preferable to use OLE or Object Linking and Embedding:

http://en.wikipedia.org/wiki/Object_Linking_and_Embedding

Only in extreme cases and when DDE/OLE are unavailable do we use SendKeys.

Kevin
Here are some examples of using SendKeys to do things in Excel that can't be done with the Excel object model:

http://blog.contextures.com/archives/2013/01/29/problems-with-sendkeys-in-excel/

Kevin
Avatar of satmisha

ASKER

Thanks Sir for your prompt reply.

But still seems my question is undone, may be I haven't mentioned it clearly, let me rephrase these:

1. Why Application.SendKeys is considered as bad practice and its impact on system.
2. Is there a better way to use replace this.
3. I appreciate if you could provide any supporting document for this.

Hopefully looking forward to hearing from you.
ASKER CERTIFIED SOLUTION
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial