habe mir mit einiger Mühe ein Fast funktionierendes Tool in Excel Programmiert.
Es soll mir mit automatischen Tastatureingaben ein SAP Fenster steuern.
Das funktioniert aber bei manchen SAP fenstern nicht mit sendkeys oder Appactivate.
Deshalb habe ich mir ein Tool zusammengebaut das auch fenster findet bzw. erkennt die Sendkeys nicht kennt.
Nur jetzt mein Problem.Dieses Makro zeigt mir Fenster an als vorhanden also findet dieses Fenster obwohl es schon geschlossen ist.ich verstehe das nicht. Es zeigt mir also an z.b das ein Fenster mit dem Namen "Dokumente offen" existiert obwohl es schon geschlossen ist. Ich verstehe das nicht ganz.Mir kommt es vor das Windows seine Fenster nicht aktualisiert ?
Würde mich sehr über Hilfe freuen.
Vielen Dank
Unten im Anhang noch ein teil meiner Routine mit dem ich prüfen ob ein fenster geöffnet ist.
Private Declare
Function GetDesktopWindow Lib "user32" () As Long
Private Declare
Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare
Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName _
As String, ByVal nMaxCount As Long) As Long
Private Declare
Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString _
As String, ByVal cch As Long) As Long
Private Declare
Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, LParam As Any) As Long
Private Declare
Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As _
Long
Private Declare
Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal wIndx As _
Long) As Long
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Const WM_CLOSE = &H10
Const GWL_STYLE = (-16)
Const WS_VISIBLE = &H10000000
Const WS_BORDER = &H800000
Function Check_Fenster(fenstername)
Dim offen As Boolean
Dim hWnd As Long, A As Long
Dim Titel$, Result$
'A = Cells(Rows.Count, 1).End(xlUp).Row
hWnd = GetDesktopWindow()
hWnd = GetWindow(hWnd, GW_CHILD)
Do While hWnd 0
Style = GetWindowLong(hWnd, GWL_STYLE)
Style = Style And (WS_VISIBLE Or WS_BORDER)
Result = GetWindowTextLength(hWnd) + 1
Titel = Space$(Result)
Result = GetWindowText(hWnd, Titel, Result)
Titel = Left$(Titel, Len(Titel) - 1)
If Style = WS_BORDER = False Then ' Alle fenster werden angezeigt nicht nur sichtbare
'If (Style = (WS_VISIBLE Or WS_BORDER) = True) Then ' Es werden nur sichtbare Fenster _
angezeigt
If Titel > "" Then
'Titel des Fensters = gewünschtem Titel
If Titel = fenstername Then
'MsgBox ("Fenster ist gerade offen gefunden ")
Check_Fenster = True
Exit Function
End If
'A = A + 1
'Cells(A, 1) = Titel
'Cells(A, 2) = hWnd
End If
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT) ' nächstes Fenster
Loop
'If offen = False Then
'Call Check_Fenster(fenstername)
'Else
'End If
'Check_Fenster = True
End Function
Die Aufrufe dieser Routine sehen so aus:
Do While ergebniss = False
ergebniss = Check_Fenster("Dokumentliste nach Selektion")
Loop
ergebniss = False