Consulting

Results 1 to 11 of 11

Thread: Is that possible to excute code by using Keboards "CTRl+Eneter"

  1. #1

    Question Is that possible to excute code by using Keboards "CTRl+Eneter"

    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?
    [vba]Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    Selection.Copy Sheets(2).Range("a1")
    End Sub[/vba]

  2. #2
    I tried this but didn't succeed
    [VBA]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[/VBA]

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    what you are trying to do is unclear to me.

    can you be more specific?
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    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
    [vba]Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 13 Then MsgBox ("Ok ")
    End Sub[/vba]
    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

  5. #5
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    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/h...-54594532.html
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  6. #6
    Thank you for help!

  7. #7
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Well, you can do your own hot key
    [vba]
    Application.OnKey "^%{RIGHT}", "ShowHideAutoloadButton"
    [/vba]

    [vba]
    Application.OnKey "^%{RIGHT}", ""
    [/vba]
    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.

  8. #8
    Quote Originally Posted by JKwan
    Well, you can do your own hot key
    [vba]
    Application.OnKey "^%{RIGHT}", "ShowHideAutoloadButton"
    [/vba]
    [vba]
    Application.OnKey "^%{RIGHT}", ""
    [/vba] 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

  9. #9
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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:
    [VBA]Private Sub Workbook_Activate()
    Application.OnKey "%^/", "SelectCopy"
    End Sub

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

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

  10. #10
    I tried your way but didn't succeed with me. Here is the file "Book1" in the attachment.
    Thank you for your effort
    Attached Files Attached Files

  11. #11
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •