SendKeyys command turns off Numlock
Here's my situation...I have a spreadsheet where I want the Comment Box to open whenever data is typed into a cell. I found the code below and it works great with one small exception: the Numlock key turns off when the macro is enable in Excel. From everything I can find online, it seems to be the SendKeys command that is causing this to happen. Now, being honest, it's not a big deal to click the Numlock key to turn it back on while the macro is enabled. But I'd sure like to find out how this can be re-written so that the Numlock key doesn't turn off.
Any help would be greatly appreciated.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Static sName As String
Dim iLen As Long
If Len(sName) = 0 Then sName = Application.UserName & ":"
With Target(1)
If Intersect(.Cells, Range("B1:Q35")) Is Nothing Then Exit Sub
If .HasFormula Then Exit Sub
If .Value = Cells(.Row, "AB").Value Then
If bHasComment(.Cells) Then .Comment.Delete
Else
.Select
If Not bHasComment(.Cells) Then
.AddComment
Else
iLen = Len(.Comment.Shape.TextFrame.Characters.Text)
End If
With .Comment.Shape.TextFrame
.AutoSize = False
.Characters(Start:=iLen + 1).Insert IIf(iLen, vbLf, "") & sName & vbLf
.Characters(Start:=iLen + 1, Length:=Len(sName)).Font.Bold = True
End With
With .Comment
.Visible = True
Application.SendKeys "+{F2}"
.Visible = False
End With
End If
End With
End Sub
Function bHasComment(cell As Range) As Boolean
On Error Resume Next
bHasComment = cell.Comment.Parent.Address = cell.Address
End Function