Share via

UserForm turning off Num Lock

Anonymous
2014-08-18T15:45:18+00:00

Hello,

   Has anyone experienced an issue where the Num Lock function is being turned off when a UserForm opens? If so, have you figured out a way to prevent this?

Thank you,

DFournier

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2014-08-18T17:28:48+00:00

Hi D,

I have not encountered this problem and if, as you suggest, your code should be exculpated,  I am unable usefully to speculate on possible alternative causes, 

However, perhaps you could use code posted by Rick Rothstein, MVP - Excel at

http://answers.microsoft.com/en-us/office/forum/office_2010-excel/checking-for-numlock-status-fixing-numlock-status/1f85d47b-c368-4de8-becd-039f947a50ba

to turn the NumLock on.

In a standard module, before and outside of any other procedure code,  paste:

'==========>>

Private Const VER_PLATFORM_WIN32_NT = 2

Private Const VER_PLATFORM_WIN32_WINDOWS = 1

Private Const VK_NUMLOCK = &H90

Private Const KEYEVENTF_EXTENDEDKEY = &H1

Private Const KEYEVENTF_KEYUP = &H2

'---------->>

Private Type OSVERSIONINFO

    dwOSVersionInfoSize As Long

    dwMajorVersion As Long

    dwMinorVersion As Long

    dwBuildNumber As Long

    dwPlatformId As Long

    szCSDVersion As String * 128

End Type

'---------->>

Private Declare Function GetVersionEx Lib "kernel32" _

                                      Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) _

                                      As Long

'---------->>

Private Declare Sub keybd_event Lib "user32" _

                                (ByVal bVk As Byte, _

                                 ByVal bScan As Byte, _

                                 ByVal dwFlags As Long, ByVal dwExtraInfo _

                                                        As Long)

'---------->>

Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) _

                                          As Long

'---------->>

Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long

'---------->>

Public Sub TurnNumLockOn()

    Dim bytKeys(255) As Byte, bnumLockOn As Boolean, typOS As OSVERSIONINFO

    GetKeyboardState bytKeys(0)

    bnumLockOn = bytKeys(VK_NUMLOCK)

    If Not bnumLockOn Then

        If typOS.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then

            bytKeys(VK_NUMLOCK) = 1

            SetKeyboardState bytKeys(0)

        Else

            keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0

            keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0

        End If

    End If

End Sub

'<<==========

Now, in your code which displays / initiates the Userform, try adding the instruction:

     Call TurnNumLockOn

===

Regards,

Norman

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2014-08-18T16:47:48+00:00

    Thanks Karl for your reply, but as I did all the designing and programming I know there are no macros or VBA code that affect the Num Lock function.

    Can you suggest anything else?

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-08-18T16:31:09+00:00

    Check the means used to open the form - macros might be doing it.

    Was this answer helpful?

    0 comments No comments