Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Setting Keyboard Functions

  1. #1
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Good morning, everyone. I was wondering if any one knew of a way to set, under macro control, the "Caps Lock" function on the keyboard?

  2. #2
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-05-11 06:37, elgringo56 wrote:
    Good morning, everyone. I was wondering if any one knew of a way to set, under macro control, the "Caps Lock" function on the keyboard?
    If you mean Turn caps Lock On/Off then you
    need some APIs


    Option Explicit
    Private Const VK_CAPITAL = &H14

    Private Type KeyboardBytes
    kbByte(0 To 255) As Byte
    End Type

    Private kbArray As KeyboardBytes
    Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Long
    Private Declare Function GetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long
    Private Declare Function SetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long

    Sub Caps_On()
    GetKeyboardState kbArray
    kbArray.kbByte(VK_CAPITAL) = 1
    SetKeyboardState kbArray
    MsgBox "Caps Lock is On"
    End Sub


    Sub Caps_Off()
    GetKeyboardState kbArray
    kbArray.kbByte(VK_CAPITAL) = 0
    SetKeyboardState kbArray
    MsgBox "Caps Lock is Off"
    End Sub

    Sub Toggle_OnOff()
    GetKeyboardState kbArray
    kbArray.kbByte(VK_CAPITAL) = Not (kbArray.kbByte(VK_CAPITAL))
    SetKeyboardState kbArray
    MsgBox "Caps Lock is On:= " & Not (kbArray.kbByte(VK_CAPITAL) = 0)
    End Sub



    _________________
    Kind Regards,
    Ivan F Moala

    Have a Nice day

    [ This Message was edited by: Ivan F Moala on 2002-05-11 06:57 ]

  3. #3

    Join Date
    May 2002
    Posts
    8
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Alternatively, if you just want to force all input to be capitals :-

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range
    Application.EnableEvents = False
    For Each cell In Selection
    If cell.HasFormula = False Then
    cell.Value = UCase(cell.Value)
    End If
    Next
    Application.EnableEvents = True
    End Sub

  4. #4
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    WOW! Thanks, guys. I am a novice so I will have to mull both of these over for a bit to see if I can understand them. Geez, and I thought there would be something simple like ActiveSheet.CapsLockOn or ActiveSheet.CapsLockOff. LOL, silly me thinking that might happen.

  5. #5
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Ivan, I'm trying to figgure out how to plug all or part of this into my macro and make it do something. There is much I do not know about programing and VB. Learning by trial and error. Mostly error.

  6. #6
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-05-11 07:41, elgringo56 wrote:
    Ivan, I'm trying to figgure out how to plug all or part of this into my macro and make it do something. There is much I do not know about programing and VB. Learning by trial and error. Mostly error.
    What do you want to do AND
    What code do you have that you want to modify

    If I can help then Post.....
    Kind Regards,
    Ivan F Moala From the City of Sails

  7. #7
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Well, I am trying to figgure out this code you gave me for turning on and off caps lock, but I get an error on it as it is. Not sure what I am doing here

  8. #8
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    What I did was open a new workbook, then make a simple select macro. Then I copied pasted what you gave me into it and tried to run it. It gave me a complie error. Now trying to figgure out just what it is

  9. #9
    MrExcel MVP
    Join Date
    Apr 2002
    Location
    Vancouver BC , Canada
    Posts
    6,259
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Could you not also use the Sendkeys vb command for the desired effect ?

    i.e. Sendkeys "CAPS LOCK" ,True

    Which can also be used for such keys as :BACKSPACE,BREAK,CAPS LOCK,DEL,DOWN ARROW,END,ENTER,ESC,HELP,HOME,INS or INSERT,LEFT ARROW,NUM LOCK,PAGE DOWN,PAGE UP,PRINT SCREEN,RIGHT ARROW,SCROLL LOCK,TAB,UP ARROW ,F1-F12



    [ This Message was edited by: nimrod on 2002-05-11 08:50 ]

  10. #10
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I will try that, Nimrod and see, thanks

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •