Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
#If VBA7 Then
Private Declare PtrSafe Function IUnknown_GetWindow Lib "shlwapi" Alias "#172" (ByVal pIUnk As IUnknown, ByVal hUF As LongPtr) As Long
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 GetWindowRect Lib "user32" (ByVal hwnd As LongPtr, lpRect As RECT) As Long
Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
#Else
Private Declare Function IUnknown_GetWindow Lib "shlwapi" Alias "#172" (ByVal pIUnk As IUnknown, ByVal hUF As Long) As Long
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
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
#End If
Private Sub UserForm_Click()
Const SM_CXFRAME = 32&, SM_CYFRAME = 33&
Dim tRect As RECT
#If Win64 Then
Const NULL_PTR = 0^
Dim hwnd As LongLong
#Else
Const NULL_PTR = 0&
Dim hwnd As Long
#End If
Call IUnknown_GetWindow(Me, VarPtr(hwnd))
Call GetWindowRect(Application.hwnd, tRect)
With tRect
.Left = .Left - 2& * GetSystemMetrics(SM_CYFRAME)
.Right = (.Right - .Left) + 2& * GetSystemMetrics(SM_CYFRAME)
.Bottom = (.Bottom - .Top) + 2& * GetSystemMetrics(SM_CXFRAME)
Call SetWindowPos(hwnd, NULL_PTR, .Left, .Top, .Right, .Bottom, ByVal 0&)
End With
End Sub