Solved

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

Posted on 2014-03-03
4
3,883 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now