Solved

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

Posted on 2014-03-03
4
3,954 Views
Last Modified: 2014-03-04
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,
0
Comment
Question by:satmisha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 39902509
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
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 39902512
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
0
 

Author Comment

by:satmisha
ID: 39904462
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.
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 145 total points
ID: 39904930
> Why Application.SendKeys is considered as bad practice and its impact on system.

As I stated above, 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.

As far as impact on the system, there is virtually no impact on the system in terms of resource utilization. Not more than any other technique anyway.

> Is there a better way to use replace this.

As I stated above, there are two more acceptable and robust methods: DDE and OLE. See my first post above for details and links to extensive descriptions of these technologies.

Kevin
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question