Activar bloque de mayúscula con macros

Me gustaría un macros que con un botón me active el bloque de mayúscula si no esta activado

Y con otro botón que la desactive si no esta activada

Por la situación del archivo de excel me es + practico activar con un botón y desactivar con otro...

1 respuesta

Respuesta
2

La instrucción desde VBA es esta:

Sub caps()
SendKeys "{capslock}", True
DoEvents
End Sub

Saludos.DAM
Si es lo que necesitas.

me funciona pero también se activa y desactiva el bloq num, y no necesito activar el bloq num................

Pon lo siguiente en un módulo.

La macro que debes ejecutar se llama mayus

' Declare Type for API call:
    Private Type OSVERSIONINFO
        dwOSVersionInfoSize As Long
        dwMajorVersion As Long
        dwMinorVersion As Long
        dwBuildNumber As Long
        dwPlatformId As Long
        szCSDVersion As String * 128   '  Maintenance string for PSS usage
    End Type
' API declarations:
    Private Declare Function GetVersionEx Lib "kernel32" _
        Alias "GetVersionExA" _
        (lpVersionInformation As OSVERSIONINFO) As Long
    Private Declare Sub keybd_event Lib "user32" _
        (ByVal bVk As Byte, _
        ByVal bScan As Byte, _
        ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    Private Declare Function GetKeyboardState Lib "user32" _
        (pbKeyState As Byte) As Long
    Private Declare Function SetKeyboardState Lib "user32" _
        (lppbKeyState As Byte) As Long
' Constant declarations:
    Const VK_NUMLOCK = &H90
    Const VK_SCROLL = &H91
    Const VK_CAPITAL = &H14
    Const KEYEVENTF_EXTENDEDKEY = &H1
    Const KEYEVENTF_KEYUP = &H2
    Const VER_PLATFORM_WIN32_NT = 2
    Const VER_PLATFORM_WIN32_WINDOWS = 1
Sub mayus()
'Referencia: http://support.microsoft.com/kb/177674
    Dim o As OSVERSIONINFO
    Dim NumLockState As Boolean
    Dim ScrollLockState As Boolean
    Dim CapsLockState As Boolean
    o.dwOSVersionInfoSize = Len(o)
    GetVersionEx o
    Dim keys(0 To 255) As Byte
    GetKeyboardState keys(0)
    ' CapsLock handling:
    CapsLockState = keys(VK_CAPITAL)
    If CapsLockState <> True Then    'Turn capslock on
        If o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then  '=== Win95/98
            keys(VK_CAPITAL) = 1
            SetKeyboardState keys(0)
        ElseIf o.dwPlatformId = VER_PLATFORM_WIN32_NT Then   '=== WinNT
            'Simulate Key Press
            keybd_event VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0
            'Simulate Key Release
            keybd_event VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY _
            Or KEYEVENTF_KEYUP, 0
        End If
    Else
        keybd_event VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0
        keybd_event VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY _
        Or KEYEVENTF_KEYUP, 0
    End If
End Sub

Saludos.DAM
No olvides finalizar la pregunta.

todo este código va en un modulo, dado que lo coloque en uno y me aparece el siguiente mensaje:

los comentarios solo pueden aparecer después de un end sub, end .........

y subrralla en el área del código siguiente

Private Declare Function GetVersionEx Lib "kernel32" _
Alias "GetVersionExA" _
(lpVersionInformation As OSVERSIONINFO) As Long

Revisa bien, crea un nuevo módulo y copia todo

copio y pego todo lo de abajo en un modulo y sigue saliéndome el mismo mensaje

Los comandos abajo en negrita es donde sequedad y manda el mensaje

' Declare Type for API call:
KEYEVENTF_EXTENDEDKEY Or 0, 0
keybd_event VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY _
Or KEYEVENTF_KEYUP, 0
End If
End Sub

No estás copiando bien la macro

Te anexo un archivo, en la hoja va un botón, presiona para que veas que prende y apaga el bloque de mayúsculas.

Revisa el código.

https://www.dropbox.com/s/gq2hl88jec65tkg/mayus.xlsm

Saludos. DAM
No olvides finalizar la pregunta.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas