AW: Event wenn von Excel in ein anderes Programm gew.
14.07.2010 17:42:34
Nepumuk
Hallo Peter,
so etwas gibt es nicht. Du kannst aber prüfen, ob das Handle des aktiven Fensters das selbe ist wie deine Application. Das ganze muss dann in einer Zeitschleife z.B. alle 100 Millisekunden überprüft werden. Hier mal das Grundgerüst:
' **********************************************************************
' Modul: DieseArbeitsmappe Typ: Element der Mappe(Sheet, Workbook, ...)
' **********************************************************************
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call StopTimer
End Sub
Private Sub Workbook_Open()
Call StartTimer
End Sub
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
Option Private Module
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 Declare Function GetActiveWindow Lib "user32.dll" () As Long
Private lblnLostFocus As Boolean
Public Sub StartTimer()
Call SetTimer(Application.hWnd, 0, 100, AddressOf TimerEvent) '100 Millisekunden
End Sub
Public Sub StopTimer()
Call KillTimer(Application.hWnd, 0)
End Sub
Private Sub TimerEvent(ByVal hWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long)
On Error Resume Next
If GetActiveWindow <> Application.hWnd Then
If Not lblnLostFocus Then
lblnLostFocus = True
'Hier kommt dein Code
End If
Else
lblnLostFocus = False
End If
End Sub
Gruß
Nepumuk