AW: was soll das ?
02.05.2014 10:14:02
Nepumuk
Hallo,
in das Modul DieseArbeitsmappe:
' **********************************************************************
' Modul: DieseArbeitsmappe Typ: Element der Mappe(Sheet, Workbook, ...)
' **********************************************************************
Option Explicit
Private Sub Workbook_Activate()
Call TimerStart
End Sub
Private Sub Workbook_Deactivate()
Call TimerStop
End Sub
in ein normales Modul:
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
Private Declare Function GetKeyboardState Lib "user32.dll" ( _
ByRef kbArray As KeyboardBytes) As Long
Private Declare Function SetTimer Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
Private Type KeyboardBytes
kbByte(0 To 255) As Byte
End Type
Public Sub TimerStart()
Call SetTimer(Application.hwnd, 0&, 100&, AddressOf TimerRun)
End Sub
Public Sub TimerStop()
Call KillTimer(Application.hwnd, 0&)
End Sub
Public Sub TimerRun( _
ByVal pvlngHwnd As Long, _
ByVal pvlngEventID As Long, _
ByVal pvlngElapse As Long, _
ByVal pnlngTimerFunction As Long)
Call ReadKeyboard
End Sub
Private Sub ReadKeyboard()
Dim udtkbArray As KeyboardBytes
Call GetKeyboardState(udtkbArray)
If udtkbArray.kbByte(vbKeyCapital) > 0 Then
If Not FormVisible(UserForm1) Then
Call UserForm1.Show
DoEvents
End If
Else
If FormVisible(UserForm1) Then
Call Unload(Object:=UserForm1)
DoEvents
End If
End If
End Sub
Private Function FormVisible( _
ByRef probjForm As Object) As Boolean
Dim objForm As Object
For Each objForm In UserForms
If objForm.Name = probjForm.Name Then
FormVisible = objForm.Visible
Exit For
End If
Next
End Function
In der Prozedur ReadKeyboard den Userformnamen anpassen! Und du musst im Userform die Möglichkeit des Schließens unterbinden, denn der Timer würde es immer wieder ausrufen solange die CapsLock-Taste gedrückt ist.
Gruß
Nepumuk