+ Reply to Thread
Results 1 to 3 of 3

Assign 2 different values/behaviours to a key

Hybrid View

Wizz Assign 2 different... 05-28-2010, 08:53 AM
antoka05 Re: Assign 2 different... 05-28-2010, 11:02 AM
Wizz Re: Assign 2 different... 05-28-2010, 12:14 PM
  1. #1
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    2003 & 2010
    Posts
    186

    Assign 2 different values/behaviours to a key

    Hi,
    I need to give 2 different behaviours to the {ENTER} key. If the {ENTER} key is pressed on sheet "Test", it should pop out a msgBox. Everywere else it should act as a normal {ENTER} key.

    So far I used the following code to catch up when enter is pressed.
    Application.OnKey "{ENTER}", "myEnterBehaviour"
    On the procedure "myEnterBehaviour" I check the worksheet name and then take an action. Poping Up the msgBox is no problem; my problem is making it act normal ! How can I Achieve that?

    My Code so Far:

    
    Private Sub Workbook_Activate()
    
        Application.OnKey "{ENTER}", "myEnterBehaviour"
    
    End Sub
    '
    
    Sub myEnterBehaviour()
        If ActiveSheet.Name = "Test" Then
           MsgBox "You just pressed Enter"
            
        Else
          'Act like a normal ENTER key - Here is where I need the help. !!!
          
        End If
        '
    End Sub
    '
    Thanks !

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Assign 2 different values/behaviours to a key

    Try to put this code only in "Test" sheet so it will call myEnterBehaviour sub only for that sheet
    Private Sub Worksheet_Activate()
       Application.OnKey "{ENTER}", "myEnterBehaviour"
    End Sub
    Private Sub Worksheet_Deactivate()
       Application.OnKey "{ENTER}"
    End Sub
    Regards,
    Antonio

  3. #3
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    2003 & 2010
    Posts
    186

    Re: Assign 2 different values/behaviours to a key

    Gracias Antonio !
    The problem with this approach is when the following happen

    1.Sheet "Test" activate
    2.User deactivate macros
    3.Moves to another sheet or workbook
    4.activate macros or run a macro throug a button.

    I was using that approach, but now I need something more 'user proof' !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1