Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-03-03
4
Medium Priority
?
4,072 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 580 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

618 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