AW: Prüfung, ob Outlook schon einmal gestartet wurde
24.02.2012 22:25:04
Patrick
hier ein Code mit die
Function IsOutlookOpen als Lösungvorschlag:
Option Explicit
Declare
Function GetWindow Lib "user32" (ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Declare
Function GetDesktopWindow Lib "user32" () As Long
Declare
Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) _
As Long
Sub TestMe()
MsgBox IsOutlookOpen
MsgBox IsOutlookAppAvailable
End Sub
Function IsOutlookAppAvailable() As Boolean
Dim myOlApp As Object
'On erro GoTo Recover
Set myOlApp = CreateObject("Outlook.Application")
IsOutlookAppAvailable = True
Exit Function
Recover:
IsOutlookAppAvailable = False
End Function
Function IsOutlookOpen() As Boolean
Dim i As Integer
Dim sWindowText As String
Dim sClassname As String
Dim sID As Long, hwnd As Long
Dim r As Long
Const GWL_ID = (-12)
Const GW_HWNDNEXT = 2
Const GW_CHILD = 5
sID = GetDesktopWindow()
i = 0
Do
If i = 1 Then
hwnd = GetWindow(sID, GW_CHILD)
Else
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
End If
If hwnd = 0 And i > 10 Then Exit Do
sWindowText = Space(255)
r = GetWindowText(hwnd, sWindowText, 255)
sWindowText = Left(sWindowText, r)
If InStr(sWindowText, "Outlook") > 0 Then
IsOutlookOpen = True
Exit Function
End If
If i > 5000 Then Stop
DoEvents
i = i + 1
Loop
IsOutlookOpen = False
End Function