Basic Excel VBA turns number lock off, I've no idea why

125 Views Asked by At

This is the code that I use regularly fired from a Button (Form Control) that is stored in PERSONAL.XLSB and therefore available universally on this PC.

Sub Today()

    Dim Today As Date
    
    Today = Date
    
    ActiveCell.Value = Today
    
    Application.SendKeys "{TAB}"
    
End Sub

Immediately after using that button the number lock is turned off.

1

There are 1 best solutions below

1
CLR On BEST ANSWER

It's a known issue. You could try using shell's SendKeys instead:

Sub Today()

    Dim Today As Date
    
    Today = Date
    
    ActiveCell.Value = Today

    Dim WshShell As Object            
    Set WshShell = CreateObject("WScript.Shell")
    WshShell.SendKeys "{TAB}", True
    
End Sub

However, as FunThomas points out in comments - there are better ways of manipulating the 'cursor'.