bezugnehmend auf diesen Thread https://www.herber.de/forum/archiv/1896to1900/1898854_Userform_in_Taskleiste.html#1899622
@Karl-Heinz und @Nepumuk, das minimieren funktioniert grundsätzlich einwandfrei und das nicht das Userform Icon in der Taskleiste angezeigt wird, da kann ich mit leben, was aber ketzt nicht so gut ist das wenn das Userform minimiert wird in der Taskleiste gar kein Icon angezeigt wird, weder Excel noch das Userform, ich kann dann zur Userform nur über Alt+Umschalt zurückkehren.
Der Code sieht jetzt so aus, nach Karl-Heinz letztem Beispiel Code (SetWindowPos hab ich rausgenommen, da das UserForm nicht immer im Vordergrund sein soll.)
'UserForm in Taskleisten und Minimieren im Rahmen
Private Declare PtrSafe Function FindWindowA Lib "user32.dll" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
#If Win64 Then
Private Declare PtrSafe Function GetWindowLongA Lib "user32.dll" _
Alias "GetWindowLongPtrA" ( _
ByVal Hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLongA Lib "user32.dll" _
Alias "SetWindowLongPtrA" ( _
ByVal Hwnd As LongPtr, ByVal nIndex As Long, _
ByVal dwNewLong As LongPtr) As LongPtr
Private Declare PtrSafe Function SetClassLongA Lib "user32" _
Alias "SetClassLongPtrA" ( _
ByVal Hwnd As LongPtr, ByVal nIndex As Long, _
ByVal dwNewLong As LongPtr) As LongPtr
#Else
Private Declare PtrSafe Function GetWindowLongA Lib "user32.dll" ( _
ByVal Hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLongA Lib "user32.dll" ( _
ByVal Hwnd As LongPtr, ByVal nIndex As Long, _
ByVal dwNewLong As LongPtr) As LongPtr
Private Declare PtrSafe Function SetClassLongA Lib "user32" ( _
ByVal Hwnd As LongPtr, ByVal nIndex As Long, _
ByVal dwNewLong As LongPtr) As LongPtr
#End If
Private Declare PtrSafe Function SetWindowPos Lib "user32" ( _
ByVal Hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, _
ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long
Private Declare PtrSafe Function ShowWindow Lib "user32.dll" ( _
ByVal Hwnd As LongPtr, _
ByVal nCmdShow As Long) As Long
Private Declare PtrSafe Function SendMessageA Lib "user32.dll" ( _
ByVal Hwnd As LongPtr, _
ByVal wMsg As Long, _
ByVal wParam As LongPtr, _
ByVal lParam As Any) As LongPtr
Private Const WM_SETICON As Long = &H80
Private Const GC_CLASSNAMEUSERFORM As String = "ThunderDFrame"
Private Const GWL_EXSTYLE As Long = -20
Private Const WS_EX_APPWINDOW As LongPtr = &H40000
Private Const SW_HIDE As Long = 0
Private Const SW_SHOW As Long = 5
Private mlngptrHwnd As LongPtr
'Userform Minimieren
Private Sub mupHauptFenster_Change()
End Sub
Private Sub UserForm_Activate()
ThisWorkbook.Activate
Dim lngptrStyle As LongPtr
Call ShowWindow(Hwnd, SW_HIDE)
lngptrStyle = GetWindowLongA(Hwnd, GWL_EXSTYLE)
lngptrStyle = lngptrStyle Or WS_EX_APPWINDOW
Call SetWindowLongA(Hwnd, GWL_EXSTYLE, lngptrStyle)
Call ShowWindow(Hwnd, SW_SHOW)
End Sub
Private Property Get Hwnd() As LongPtr
Hwnd = mlngptrHwnd
End Property
Private Property Let Hwnd(ByVal pvlngptrHwnd As LongPtr)
mlngptrHwnd = pvlngptrHwnd
End Property
Private Sub UserForm_Initialize()
'Minimieren funktion im Userform
Dim Hwnd As LongPtr
Const GCL_HICON = (-14)
Const GWL_STYLE = -16&
Const WS_MINIMAXIMIZEBOX = &H30000
Const HWND_TOPMOST = -1
' Mini/Maximieren-Funktion im Userform
Hwnd = FindWindowA("ThunderDFrame", Caption) ' Handle Userform holen
SetWindowLongA Hwnd, GWL_STYLE, GetWindowLongA(Hwnd, GWL_STYLE) _
Or WS_MINIMAXIMIZEBOX ' Mini/Maxiboxen zufügen
End Sub
Danke