Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1194
  • Last Modified:

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

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
satmisha
Asked:
satmisha
  • 8
  • 4
  • 3
  • +2
1 Solution
 
Rgonzo1971Commented:
Hi,

this has been covered by MS-Support

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

Regards
0
 
Rory ArchibaldCommented:
Why do you need to send the Esc key in your code?
0
 
satmishaAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Rory ArchibaldCommented:
I'm not clear what you mean by "I am inserting value in a cell from the popup". What popup?
0
 
Rob HensonIT & Database AssistantCommented:
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
 
satmishaAuthor Commented:
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
 
Wayne Taylor (webtubbs)Commented:
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
 
satmishaAuthor Commented:
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
 
Rory ArchibaldCommented:
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
 
Wayne Taylor (webtubbs)Commented:
In the BeforeDoubleClick event, use this after any other code....

    Cancel = True

Wayne
0
 
satmishaAuthor Commented:
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
 
Rory ArchibaldCommented:
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
 
satmishaAuthor Commented:
Thanks Rory for your time, I do agree with you and will send that today evening.
0
 
satmishaAuthor Commented:
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
 
satmishaAuthor Commented:
In order to take the cursor our of the cell I need to use .sendkeys "esc" which in turn off\on num lock
0
 
Wayne Taylor (webtubbs)Commented:
Cancel = True in the BeforeDoubleClick event does exactly what you want.
0
 
satmishaAuthor Commented:
Thanks it is working.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now