![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
|
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 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
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. |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
|
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 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
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..... |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|