CAPS LOCK ON WHEN SHEET IS OPEN

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
On 2002-03-27 18:15, Eddie G. wrote:
Is the VB that will turn the CAPS LOCK on when a sheet is opened?

In the Thisworkbook object place this code;

Private Sub Workbook_Open()
Caps_On
End Sub


In A Std module place this code

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 "On"
End Sub


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


HTH

Ivan
 
Upvote 0
Hi Eddie. Ivan presented the perfect code which used API.
So, I proposed the following method as another way.
It is the method of making all letter to "capital letter" compulsorily.

'//Please copy this into a Thisworkbook Module
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Source As Range)
Dim rng As Range
With Application
.EnableEvents = False
For Each rng In Source
rng.Value = UCase(rng.Value)
Next
.EnableEvents = True
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top