Servus,
folgender Code bringt Excel wieder in den Vordergrund:
Option Explicit
' Fensterhandle ermitteln
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
' Fensterstatus festlegen
Private Declare Function ShowWindow Lib "user32" (ByVal _
hwnd As Long, ByVal nCmdShow As Long) As Long
' Fensterposition festlegen
Private Declare Function SetWindowPos Lib "user32" (ByVal _
hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
' Fensterposition ermitteln
Private Declare Function GetWindowPlacement Lib "user32" _
(ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As _
Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Private Const SW_SHOWNOACTIVATE As Long = 4
Private Const SW_SHOWMINIMIZED As Long = 2
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Const HWND_TOP As Long = 0
Public Sub BringExcelToTop()
Dim WinWnd As Long, Place As WINDOWPLACEMENT
' Fensterhandle von Excel ermitteln,
' WinWnd=0, falls Excel nicht gestartet wurde
WinWnd = FindWindow("XLMAIN", vbNullString)
' falls das Fensterhandle von Excel ermittelt
' werden konnte, Excel in den Vordergrund bringen
If WinWnd <> 0 Then
' Fensterposition von Excel ermitteln
GetWindowPlacement WinWnd, Place
' falls Excel minimiert ist,
' Fenstergröße wiederherstellen
If Place.showCmd = SW_SHOWMINIMIZED Then _
ShowWindow WinWnd, SW_SHOWNOACTIVATE
' Excel ganz nach oben bringen (Vordergrund),
' Position und Größe nicht ändern
SetWindowPos WinWnd, HWND_TOP, 0, 0, 0, 0, _
SWP_NOMOVE + SWP_NOSIZE
End If
End Sub Viel Spass,
R@lf |