Option Explicit
Dim oldcell As Range
Dim chang As Boolean
Private Sub Workbook_Open(): detourneTouche: End Sub
Public Sub updownleftright(arg As String)
chang = True
Select Case arg
Case "{UP}": If ActiveCell.Row > 1 Then ActiveCell.Offset(-1).Select
Case "{DOWN}": If ActiveCell.Row < Rows.Count Then ActiveCell.Offset(1).Select
Case "{LEFT}": If ActiveCell.Column > 1 Then ActiveCell.Offset(, -1).Select
Case "{RIGHT}": If ActiveCell.Column < Columns.Count Then ActiveCell.Offset(, 1).Select
End Select
End Sub
Sub detourneTouche()
If ActiveSheet.Index = 1 Then
Application.OnKey "{UP}", "'ThisWorkBook.updownleftright ""{UP}""'"
Application.OnKey "{DOWN}", "'ThisWorkBook.updownleftright ""{DOWN}""'"
Application.OnKey "{LEFT}", "'ThisWorkBook.updownleftright ""{LEFT}""'"
Application.OnKey "{RIGHT}", "'ThisWorkBook.updownleftright ""{RIGHT}""'"
Else
If Not oldcell Is Nothing Then oldcell.Interior.Color = xlNone
Application.OnKey "{UP}"
Application.OnKey "{DOWN}"
Application.OnKey "{LEFT}"
Application.OnKey "{RIGHT}"
End If
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object): detourneTouche: End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Not oldcell Is Nothing Then oldcell.Interior.Color = xlNone
If Sh.Index = 1 Then
If chang = True Then
Target.Interior.Color = vbRed
Set oldcell = Target
chang = False
End If
End If
End Sub