![]() |
![]() |
|
|||||||
| 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
|
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 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
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 ![]() [ This Message was edited by: Ivan F Moala on 2002-05-11 06:57 ] |
|
|
|
|
|
|
#3 |
|
Join Date: May 2002
Posts: 8
|
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 |
|
Board Regular
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
|
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 |
|
Board Regular
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
|
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 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
What code do you have that you want to modify If I can help then Post..... |
|
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
|
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 |
|
Board Regular
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
|
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 |
|
MrExcel MVP
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
|
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 |
|
Board Regular
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
|
I will try that, Nimrod and see, thanks
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|