Num lock key gets switched off

jub6

New Member
Joined
Nov 26, 2007
Messages
16
Hi

I have a macro which use to run properly for my team till last week.This week the whenever i run the macro it works but the end of it the num lock key gets switched off. The only changes that happend is we all upgraded the system to windows 7.

Regards,
John
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Upvote 0
Hi
Thanks for the reply the code is quite big and working fine ... it just exports the data from the cms to excel in every 2 minutes.
I saw the link and checked in my code am sending the keys ie
SendKeys "%ET"

and the num lock goes off is their any way to get it back if this cannot be stopped.

I hope the information helps ...

Regards,
John
 
Upvote 0
At work (XP and 2010) and too dense to remember what ALT+ET gets you. I could not get SendKeys to shut off NUMLOCK but tested against having it off manually and this seems to turn it back on:

In a Standard Module:
Rich (BB code):
Option Explicit
    
Sub NumLocks_On()
Dim o               As OSVERSIONINFO
Dim NumLockState    As Boolean
Dim ScrollLockState As Boolean
Dim CapsLockState   As Boolean
Dim keys(0 To 255)  As Byte
    
    o.dwOSVersionInfoSize = Len(o)
    GetVersionEx o
    GetKeyboardState keys(0)
    
    ' NumLock handling:
    NumLockState = keys(VK_NUMLOCK)
    If NumLockState <> True Then    'Turn numlock on
        If o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then  '=== Win95/98
            
            keys(VK_NUMLOCK) = 1
            SetKeyboardState keys(0)
        ElseIf o.dwPlatformId = VER_PLATFORM_WIN32_NT Then   '=== WinNT
            'Simulate Key Press
            keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0
            'Simulate Key Release
            keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
        End If
    End If
End Sub

In a Standard Module:
Rich (BB code):
Option Explicit
    
Public Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128   '  Maintenance string for PSS usage
End Type
    
Public Declare Function GetVersionEx Lib "kernel32" _
                        Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO _
                                               ) As Long
    
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
                                             ByVal bScan As Byte, _
                                             ByVal dwFlags As Long, _
                                             ByVal dwExtraInfo As Long _
                                             )
    
Public Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte _
                                                       ) As Long
    
Public Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte _
                                                       ) As Long
    
' Constant declarations:
Public Const VK_NUMLOCK = &H90
Public Const VK_SCROLL = &H91
Public Const VK_CAPITAL = &H14
Public Const KEYEVENTF_EXTENDEDKEY = &H1
Public Const KEYEVENTF_KEYUP = &H2
Public Const VER_PLATFORM_WIN32_NT = 2
Public Const VER_PLATFORM_WIN32_WINDOWS = 1

Not sure if any changes that would prohibit it from running correctly in Windows7.

Above excerpted from: http://support.microsoft.com/kb/177674/EN-US

I did see this (reference the bug): http://support.microsoft.com/default.aspx?kbid=179987

Hope that helps,

Mark
 
Upvote 0
hi

Have tried the same getting the error as mentioned below.

Compile Error:
User-defined type not defined
 
Upvote 0
hi

Have tried the same getting the error as mentioned below.

Compile Error:
User-defined type not defined

I'll be the first to admit that I am awefully sleepy-eyed this day, but I do not see where you mentioned any error before; just that NUMLOCK was being turned off.

Are you sure you put the code into Standard modules and not a worksheet's module?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,605
Messages
6,179,860
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top