Option Explicit
#If VBA7 Then
#If Win64 Then
Private Declare PtrSafe Function SetParent Lib "user32" (ByVal hWndChild As LongPtr, ByVal hWndNewParent As LongPtr) As Long
Private Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal HwnD As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As Long
#Else
Private Declare PtrSafe Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare PtrSafe Function GetActiveWindow Lib "user32" () As Long
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal HwnD As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#End If
#Else
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal HwnD As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#End If
Dim oldpos
Private Sub CommandButton1_Click()
End Sub
Private Sub UserForm_Activate()
Dim HwnD&, AppHwnD&
HwnD = GetActiveWindow
SetWindowLong HwnD, -16, &H94CF8080
AppHwnD = Application.HwnD
SetParent HwnD, AppHwnD
oldpos = Array(Me.Left, Me.Top, Me.Width, Me.Height)
End Sub
Private Sub UserForm_Layout()
If Me.Height > 30 Then oldpos = Array(Me.Left, Me.Top, Me.Width, Me.Height)
End Sub
Private Sub UserForm_Resize()
With Me
If .Height < 30 Then
Me.Move Application.Width - .Width, Application.Height - .Height - 6, 100, Me.Height
ElseIf .Height = oldpos(3) Then .Move oldpos(0), oldpos(1), oldpos(2), oldpos(3)
ElseIf .Height > oldpos(3) Then
End If
End With
End Sub