Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: 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

    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
    I am trying to turn on or off Keyboard lock under macro control. This morning Ivan gave me this. I know so little, I cant seem to figure out how to use it. Can anyone help?

    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

  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

    Hi ElGringo56

    Where have you placed this Code?
    - Should be in a STD Module

    How to want to initiate the code?
    - Via commandbutton or upon opening or
    some other event.


    Kind Regards,
    Ivan F Moala From the City of Sails

  3. #3
    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 dont know what an STD Module is???

    I want to initiate it as I move down thru code, or maybe as I open a sheet, hmm, may be better if I did it when I opened the sheets I want caps on. Makes sence to me.

  4. #4
    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 14:11, elgringo56 wrote:
    I dont know what an STD Module is???

    I want to initiate it as I move down thru code, or maybe as I open a sheet, hmm, may be better if I did it when I opened the sheets I want caps on. Makes sence to me.
    To get this to work when you open the workbook then.....

    From your Worksheet
    1. Press Alt-F11 to display the Visual Basic editor.

    2. In the Project Explorer window, find an entry for the Thisworkbook object. If you don't see the Project Explorer window, press Ctrl-R.

    3. Double-click on thisworkbook entry in the Project Explorer window.

    4. Paste this code here


    Private Sub Workbook_Open()
    Caps_On
    End Sub





    Is there a reason you want this on ?
    If for input reasons then there are other
    Options...ie allow users to input THEN convert.....
    Kind Regards,
    Ivan F Moala From the City of Sails

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
  •