Ich nutze den unten aufgeführten Code um ein Fenster in den Vordergrund zu bringen.
Ist das Fenster nicht geöffnet würde ich gerne den Code beenden, mit eine msgBox "Bitte Progamm öffnen"
an welcher stelle muß ich da was einfügen im Code, vor allem was?
Vielen Dank
Sebastian
Private Function GetWindowInfo(ByVal hwnd&, STitel$, Optional booVisible As Boolean = True) As _
Long
Dim Result&, Style&, Title$
'Darstellung des Fensters
Style = GetWindowLong(hwnd, GWL_STYLE)
Style = Style And (WS_VISIBLE Or WS_BORDER)
'Fensetrtitel ermitteln
Result = GetWindowTextLength(hwnd) + 1
Title = Space$(Result)
Result = GetWindowText(hwnd, Title, Result)
Title = Left$(Title, Len(Title) - 1)
'prüfen ob Fenster Sichtbar
If (Style = (WS_VISIBLE Or WS_BORDER)) Or booVisible = False Then
If Title Like "*" & STitel & "*" Then
GetWindowInfo = hwnd
Exit Function
End If
End If
GetWindowInfo = 0
End Function
Sub FensterSuchen()
Dim hwnd As Long
Dim STitel As String
STitel = "MeineFenstertitel"
hwnd = GetDesktopWindow()
hwnd = GetWindow(hwnd, GW_CHILD)
GetWindowInfo hwnd, STitel, True
Do While hwnd 0
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
If GetWindowInfo(hwnd, STitel, True) = hwnd Then
ShowWindow hwnd, iNormal 'maximieren
SetForegroundWindow hwnd 'aktivieren
Dim Rec As RECT
GetWindowRect GetForegroundWindow, Rec
End If
Loop
starte_makro
End Sub