Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Can macro type "vbKeyNumpad5" into a cell - to check for NumLock o

I've seen the programming test for NumLock and it appears pretty complicated.
Would it be possible for a macro to simulate pressing the 5 key on the
number pad to see what the result is? If you get a 5, NumLock would be on,
if you get nothing, NumLock would be off.

I have tried this with SendKeys and all I get is 101 the code for the key.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Can macro type "vbKeyNumpad5" into a cell - to check for NumLock o

I'm not sure what code you looked at, but I don't think the test for the
NumLock being on or off is *that* complicated. Copy/paste this code into a
Module (Insert/Module from the VB editor's menu bar)...

' *************** START OF CODE ***************
Private Declare Function GetKeyboardState Lib "user32" _
(pbKeyState As Byte) As Long

Private Const VK_NUMLOCK = &H90

Public Function IsNumLockOn() As Boolean
Dim bytKeys(255) As Byte
GetKeyboardState bytKeys(0)
IsNumLockOn = bytKeys(VK_NUMLOCK)
End Function
' *************** END OF CODE ***************

To use it, simple call the IsNumLockOn function... it will return True if
the NumLock is on and False if it is not on.

If IsNumLockOn Then
MsgBox "The NumLock is on!"
Else
MsgBox "The NumLock is not on."
End If

--
Rick (MVP - Excel)


"Steve" wrote in message
...
I've seen the programming test for NumLock and it appears pretty
complicated.
Would it be possible for a macro to simulate pressing the 5 key on the
number pad to see what the result is? If you get a 5, NumLock would be
on,
if you get nothing, NumLock would be off.

I have tried this with SendKeys and all I get is 101 the code for the
key.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Can macro type "vbKeyNumpad5" into a cell - to check for NumLo

What I found was on the Microsoft site and the programming appeared to be at
least one page long. I'll try what you gave me - Thanks.

"Rick Rothstein" wrote:

I'm not sure what code you looked at, but I don't think the test for the
NumLock being on or off is *that* complicated. Copy/paste this code into a
Module (Insert/Module from the VB editor's menu bar)...

' *************** START OF CODE ***************
Private Declare Function GetKeyboardState Lib "user32" _
(pbKeyState As Byte) As Long

Private Const VK_NUMLOCK = &H90

Public Function IsNumLockOn() As Boolean
Dim bytKeys(255) As Byte
GetKeyboardState bytKeys(0)
IsNumLockOn = bytKeys(VK_NUMLOCK)
End Function
' *************** END OF CODE ***************

To use it, simple call the IsNumLockOn function... it will return True if
the NumLock is on and False if it is not on.

If IsNumLockOn Then
MsgBox "The NumLock is on!"
Else
MsgBox "The NumLock is not on."
End If

--
Rick (MVP - Excel)


"Steve" wrote in message
...
I've seen the programming test for NumLock and it appears pretty
complicated.
Would it be possible for a macro to simulate pressing the 5 key on the
number pad to see what the result is? If you get a 5, NumLock would be
on,
if you get nothing, NumLock would be off.

I have tried this with SendKeys and all I get is 101 the code for the
key.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Can macro type "vbKeyNumpad5" into a cell - to check for NumLo

I pasted your code in and added this to my programming

If Not IsNumLockOn Then
SendKeys "{numlock}", True
DoEvents
End If

But nothing happens (it doesn't turn NumLock back on). Does it make a
difference that I am using Excel 2003?

I am using this because I am doing a lot of interaction with another
non-Office program using SendKeys, and occasionally it turns off the NumLock,
even using DoEvents.

"Rick Rothstein" wrote:

I'm not sure what code you looked at, but I don't think the test for the
NumLock being on or off is *that* complicated. Copy/paste this code into a
Module (Insert/Module from the VB editor's menu bar)...

' *************** START OF CODE ***************
Private Declare Function GetKeyboardState Lib "user32" _
(pbKeyState As Byte) As Long

Private Const VK_NUMLOCK = &H90

Public Function IsNumLockOn() As Boolean
Dim bytKeys(255) As Byte
GetKeyboardState bytKeys(0)
IsNumLockOn = bytKeys(VK_NUMLOCK)
End Function
' *************** END OF CODE ***************

To use it, simple call the IsNumLockOn function... it will return True if
the NumLock is on and False if it is not on.

If IsNumLockOn Then
MsgBox "The NumLock is on!"
Else
MsgBox "The NumLock is not on."
End If

--
Rick (MVP - Excel)


"Steve" wrote in message
...
I've seen the programming test for NumLock and it appears pretty
complicated.
Would it be possible for a macro to simulate pressing the 5 key on the
number pad to see what the result is? If you get a 5, NumLock would be
on,
if you get nothing, NumLock would be off.

I have tried this with SendKeys and all I get is 101 the code for the
key.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How I can get "Two Hundreds and Twenty" if i type "220" in a cell AHASAN Excel Discussion (Misc queries) 2 September 29th 09 01:43 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
When I type "BVE" in a cell, it automatically chanegs to"BE"..Why ELF Excel Discussion (Misc queries) 1 July 28th 06 07:44 PM
Where is the toolbar with the "bold type", "font type", options fwccbcc New Users to Excel 2 May 3rd 06 09:11 PM
create links to check boxes marked "good" fair"and "bad" pjb Excel Worksheet Functions 3 April 20th 06 02:17 AM


All times are GMT +1. The time now is 05:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"