MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 11th, 2002, 07:37 AM   #1
elgringo56
Board Regular
 
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
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?
elgringo56 is offline   Reply With Quote
Old May 11th, 2002, 07:56 AM   #2
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
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 ]
Ivan F Moala is offline   Reply With Quote
Old May 11th, 2002, 08:00 AM   #3
Lo Lun To
 
Join Date: May 2002
Posts: 8
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
Lo Lun To is offline   Reply With Quote
Old May 11th, 2002, 08:11 AM   #4
elgringo56
Board Regular
 
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
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.
elgringo56 is offline   Reply With Quote
Old May 11th, 2002, 08:41 AM   #5
elgringo56
Board Regular
 
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
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.
elgringo56 is offline   Reply With Quote
Old May 11th, 2002, 08:49 AM   #6
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
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
Ivan F Moala is offline   Reply With Quote
Old May 11th, 2002, 09:33 AM   #7
elgringo56
Board Regular
 
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
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
elgringo56 is offline   Reply With Quote
Old May 11th, 2002, 09:36 AM   #8
elgringo56
Board Regular
 
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
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
elgringo56 is offline   Reply With Quote
Old May 11th, 2002, 09:44 AM   #9
Nimrod
MrExcel MVP
 
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
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 ]
Nimrod is offline   Reply With Quote
Old May 11th, 2002, 09:45 AM   #10
elgringo56
Board Regular
 
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
Default

I will try that, Nimrod and see, thanks
elgringo56 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 05:57 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes