โค้ดไม่มีปัญหาเวลารัน VBA ใน EXCEL 2003 ครับ แต่เวลาใช้ EXCEL 2007 จะรัน VBA ไม่ได้ครับ
Code: Select all
Option Explicit
Option Base 1
Dim i As Long
Sub KeyEventOn()
Dim a As Variant
Application.TransitionMenuKey = "\"
a = Array(95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 109, 110, 111)
For i = 1 To UBound(a)
Application.OnKey "{" & a(i) & "}", "'EnterToNextCell """ & a(i) & """'"
Next i
End Sub
Sub KeyEventOff()
Dim a As Variant
Application.TransitionMenuKey = "/"
a = Array(95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 109, 110, 111)
For i = 1 To UBound(a)
Application.OnKey "{" & a(i) & "}"
Next i
End Sub
Sub EnterToNextCell(ByVal KeyCode As Long)
Dim strText As String
Dim s As String
If Not TypeOf Selection Is Range Then Exit Sub
s = Chr(KeyCode)
Select Case s
Case "k", "n", "`": s = 0
Case "a": s = 1
Case "b": s = 2
Case "c": s = 3
Case "d": s = 4
Case "e": s = 5
Case "f": s = 6
Case "g": s = 7
Case "h", "o": s = 8
Case "j", "i", "m": s = 9
End Select
strText = Selection.Value & s
Selection.Value = strText
Select Case Selection.Column
Case 3, 12
'MsgBox "2"
If Len(Selection) >= 2 Then
Application.SendKeys "{ENTER}"
End If
Case 6, 9, 15
'MsgBox "5"
If Len(Selection) >= 3 Then
Application.SendKeys "{ENTER}"
End If
End Select
End Sub