AW: Excel minimiert lassen während UserForm aktiv
27.03.2015 17:31:42
Nepumuk
Hallo,
Jetzt hab ich die Bedingungen genauer gelesen. :-\
Wie wäre es, wenn das UserForms in der Taskleiste erscheint wie ein normales Fenster?
Beispiel für Excel 2002-2007:
Option Explicit
Private Declare Function FindWindowA Lib "user32.dll" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLongA Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLongA Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function SetActiveWindow Lib "user32.dll" ( _
ByVal hwnd As LongPtr) As Long
Private Const GWL_EXSTYLE As Long = -20&
Private Const WS_EX_APPWINDOW As Long = &H40000
Private Const GC_CLASSNAMEUSERFORM As String = "ThunderDFrame"
Private Sub UserForm_Activate()
Dim lngFormHwnd As Long, lngStyle As Long
Application.Visible = False
lngFormHwnd = FindWindowA(GC_CLASSNAMEUSERFORM, Caption)
lngStyle = GetWindowLongA(lngFormHwnd, GWL_EXSTYLE)
lngStyle = lngStyle Or WS_EX_APPWINDOW
Call SetWindowLongA(lngFormHwnd, GWL_EXSTYLE, lngStyle)
Call SetActiveWindow(Application.hwnd)
Call SetActiveWindow(lngFormHwnd)
End Sub
Private Sub UserForm_Terminate()
Application.Visible = True
End Sub
Für Excel ab 2010 32 und 64 Bit:
Option Explicit
Private Declare PtrSafe Function FindWindowA Lib "user32.dll" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function GetWindowLongA Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByVal nIndex As Long) As Long
Private Declare PtrSafe Function SetWindowLongA Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function SetActiveWindow Lib "user32.dll" ( _
ByVal hwnd As LongPtr) As Long
Private Const GWL_EXSTYLE As Long = -20&
Private Const WS_EX_APPWINDOW As Long = &H40000
Private Const GC_CLASSNAMEUSERFORM As String = "ThunderDFrame"
Private Sub UserForm_Activate()
Dim lngptrFormHwnd As LongPtr
Dim lngStyle As Long
Application.Visible = False
lngptrFormHwnd = FindWindowA(GC_CLASSNAMEUSERFORM, Caption)
lngStyle = GetWindowLongA(lngptrFormHwnd, GWL_EXSTYLE)
lngStyle = lngStyle Or WS_EX_APPWINDOW
Call SetWindowLongA(lngptrFormHwnd, GWL_EXSTYLE, lngStyle)
Call SetActiveWindow(CLngPtr(Application.hwnd))
Call SetActiveWindow(lngptrFormHwnd)
End Sub
Private Sub UserForm_Terminate()
Application.Visible = True
End Sub
Gruß
Nepumuk