Solved

Alternative to Application.SendKeys "Esc" as it is turning off/On num lock in the VBA

Posted on 2015-02-11
17
571 Views
Last Modified: 2016-02-10
Hi Experts,
I am using Application.SendKeys "Esc", True

in VBA code which works fine only issue is it automatically turns On & off Num Lock.

I have searched the net and found we should avoid sendkeys. Is there any alternative to this or any workaround ?

Looking forward to hearing frmo you.
0
Comment
Question by:satmisha
  • 8
  • 4
  • 3
  • +2
17 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 40603106
Hi,

this has been covered by MS-Support

http://support2.microsoft.com/kb/179987/en-us

Regards
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 40603168
Why do you need to send the Esc key in your code?
0
 

Author Comment

by:satmisha
ID: 40603400
I am inserting value in a cell from the popup which works fine but my cursor\pointer stays inside the cell and in order to take the cursor out of that cell I need to press esc key from keyboard.

I want to automate that by itself by using sendkeys but that leads me to another problem of num lock.

Please feel free to let me know you need more information.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 40603554
I'm not clear what you mean by "I am inserting value in a cell from the popup". What popup?
0
 
LVL 32

Expert Comment

by:Rob Henson
ID: 40603601
If you do need to go down the SendKeys route, pressing Esc will cancel entry in the cell; surely you need to press Enter.

Thanks
Rob H
0
 

Author Comment

by:satmisha
ID: 40603666
Thanks for your reply.

Apologies for confusion, I am taking values from user form to sheet. When value comes in a cell the focus\cursor remains inside the cell in order to take the cursor\focus out of the cell or on the cell I need to press Esc key.

Want to automate the manual way of doing Esc key, so I used
application.SendKeys "Esc",True
Snippet but it took me to the another problem of num lock on and off.

Requirement:
Is there a way other than sendkeys to simulate Esc key in VBA ? if yes then what I have to do.


I hope this would clear my requirement. Please feel free if you require any other info.
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 40604630
How are you "taking values from user form to sheet"? If you use something like this....

    Worksheets("Sheet1").Range("A1").Value = TextBox1.Text

...the cell does not receive focus.
0
 

Author Comment

by:satmisha
ID: 40605169
I am using

On the user form I am using:
 ActiveCell.value = cmbTiger.value
and on the Worksheet_BeforeDoubleClick event I am using this to take the cursor from the cell
 Application.SendKeys "{ESC}", True
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 85

Expert Comment

by:Rory Archibald
ID: 40605184
I'm baffled as to why you need Esc. That line of code would not put the cell in edit mode, so what exactly do you mean by "take the cursor from the cell"?
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 40605217
In the BeforeDoubleClick event, use this after any other code....

    Cancel = True

Wayne
0
 

Author Comment

by:satmisha
ID: 40605220
I have tried cancel = True but it didnt work.

Rory Archibald : "take the cursor from the cell"?
It means that my cursor stays inside the cell and if i try to navigate up or down i can not unless untill I press escape key to bring down the focus on the active cell.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 40605252
Can you post a workbook showing what you mean? I cannot fathom what your actual problem is currently as nothing you have posted indicates a need to press Esc.
0
 

Author Comment

by:satmisha
ID: 40605260
Thanks Rory for your time, I do agree with you and will send that today evening.
0
 

Author Comment

by:satmisha
ID: 40607585
Apologies for late reply.
1. In the worksheet before double click event use following line
userForm. Show
2. In user Form button click use use
activeCell. Value="aa"
Me.hide

You would see when control comes on worksheet than cursor remain inside the cell rather on the cell.
0
 

Author Comment

by:satmisha
ID: 40607590
In order to take the cursor our of the cell I need to use .sendkeys "esc" which in turn off\on num lock
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 40607597
Cancel = True in the BeforeDoubleClick event does exactly what you want.
0
 

Author Closing Comment

by:satmisha
ID: 40613845
Thanks it is working.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

919 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

22 Experts available now in Live!

Get 1:1 Help Now