PDA

View Full Version : Is that possible to excute code by using Keboards "CTRl+Eneter"



Nader
02-09-2011, 06:43 AM
I tried this code to copy the selected data from any sheets to the sheets(2)
My question is it possible to excute this code by using keyborad "CTRl+Eneter"
and how?
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Selection.Copy Sheets(2).Range("a1")
End Sub

Nader
02-09-2011, 08:48 AM
I tried this but didn't succeed
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If keycode = 17+13 Then Selection.Copy Sheets(2).Range("a1")
End Sub

mancubus
02-09-2011, 03:14 PM
what you are trying to do is unclear to me.

can you be more specific?

Nader
02-09-2011, 04:06 PM
I will make it more simple
example:
If I use this code on the UserForm it will succeed. by show MesgBox "Ok" after I click on the Enter Key
Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then MsgBox ("Ok ")
End Sub
If I'm working on any sheets in the workbook. I want when I press the Enter Key to do same think as in UserForm.

Thank you for your interest

mancubus
02-09-2011, 11:54 PM
ok.



There is no keydown event for worksheet objects. Macros won't run when a
cell is in "Edit Mode" so the event wouldn't do you any good anyway. You
might consider the Worksheet_Change event. If you really need a keydown,
you will probably have to put a textbox over the cell and use the keydown
for that. It's a lot of work though.

Dick Kusleika
MVP - Excel


http://us.generation-nt.com/answer/how-do-i-capture-keydown-event-worksheet-help-54594532.html

Nader
02-10-2011, 01:18 AM
Thank you for help!

JKwan
02-10-2011, 08:58 AM
Well, you can do your own hot key

Application.OnKey "^%{RIGHT}", "ShowHideAutoloadButton"



Application.OnKey "^%{RIGHT}", ""

The first set of code, when you press Control-Alt Right Arrow, it will execute that procedure
The second set of code will remove the hot key

What I do is I put the first code in the Workbook Open, and second set in the Before close to clear the hot key.

Nader
02-13-2011, 04:08 AM
Well, you can do your own hot key

Application.OnKey "^%{RIGHT}", "ShowHideAutoloadButton"


Application.OnKey "^%{RIGHT}", ""
The first set of code, when you press Control-Alt Right Arrow, it will execute that procedure
The second set of code will remove the hot key

What I do is I put the first code in the Workbook Open, and second set in the Before close to clear the hot key.
I tried but didn't succeed

Kenneth Hobs
02-13-2011, 09:22 AM
Did you add your procedure for Onkey to a Module? There are some keys and sets of keys that Onkey will not be able to use. In this example, I used Alt+Ctrl+/.

In the ThisWorkbook object, I added:
Private Sub Workbook_Activate()
Application.OnKey "%^/", "SelectCopy"
End Sub

Private Sub Workbook_Deactivate()
Application.OnKey "%^/", ""
End Sub


In a Module:
Sub SelectCopy()
Selection.Copy ThisWorkbook.Sheets(2).Range("A1")
Application.CutCopyMode = False
End Sub

Nader
02-17-2011, 02:43 AM
I tried your way but didn't succeed with me. Here is the file "Book1" in the attachment.
Thank you for your effort

Kenneth Hobs
02-17-2011, 05:31 AM
The only way that I can duplicate your problem is when I assigned the key combination to a Windows Shortcut. Obviously, one has to govern.