AW: Danke, aber...mT
28.08.2009 20:36:13
Nepumuk
Hallo Hübi,
versuch es mal so:
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
Private Declare Function EnumWindows Lib "user32.dll" ( _
ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Boolean
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" ( _
ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" ( _
ByVal hwnd As Long) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" ( _
ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Const GC_CLASSNAMEMSEXCEL = "XLMAIN"
Private Const WM_CLOSE = &H10
Public Sub Start()
Call EnumWindows(AddressOf WindowCallBack, ByVal 0&)
End Sub
Private Function WindowCallBack(ByVal lnghWnd As Long, ByVal lngParam As Long) As Boolean
Dim strCaption As String, strClassName As String
Dim lngReturn As Long
strClassName = Space$(256)
lngReturn = GetClassName(lnghWnd, strClassName, 256)
If Left$(strClassName, lngReturn) = GC_CLASSNAMEMSEXCEL Then
lngReturn = GetWindowTextLength(lnghWnd)
strCaption = Space$(lngReturn)
Call GetWindowText(lnghWnd, strCaption, lngReturn + 1)
If strCaption <> Application.Caption Then
If MsgBox(strCaption & vbLf & vbLf & "Schließen?", _
vbQuestion Or vbYesNo, "Abfrage") = vbYes Then _
Call PostMessage(lnghWnd, WM_CLOSE, 0&, 0&)
End If
End If
WindowCallBack = True
End Function
Gruß
Nepumuk