' Written: September 12, 2017
' Author: Leith Ross
Dim OldWidth As Double
Dim OldHeight As Double
Const ZoomMin As Long = 10
Const ZoomMax As Long = 400
Private Declare Function GetForegroundWindow Lib "User32.dll" () As Long
Private Declare Function GetWindowLong _
Lib "User32.dll" Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) _
As Long
Private Declare Function SetWindowLong _
Lib "User32.dll" Alias "SetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) _
As Long
Private Declare Function ShowWindow _
Lib "User32.dll" _
(ByVal hwnd As Long, _
ByVal nCmdShow As Long) _
As Long
Private Sub MakeFormResizable()
Dim lStyle As Long
Dim hwnd As Long
Dim RetVal As Long
Const WS_MAXIMIZEBOX As Long = &H10000
Const WS_MINIMIZEBOX As Long = &H20000
Const WS_THICKFRAME As Long = &H40000
Const GWL_STYLE As Long = -16
hwnd = GetForegroundWindow
' Get the basic window style
lStyle = GetWindowLong(hwnd, GWL_STYLE) Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX
' Set the basic window styles
RetVal = SetWindowLong(hwnd, GWL_STYLE, lStyle)
End Sub
Private Sub UserForm_Activate()
MakeFormResizable
End Sub
Private Sub UserForm_Initialize()
OldWidth = Me.Width
OldHeight = Me.Height
End Sub
Private Sub UserForm_Resize()
Dim CurStyle As Long
Dim tmpZoom As Double
Const WS_MAXIMIZE As Long = &H1000000
CurStyle = GetWindowLong(GetForegroundWindow, GWL_STYLE)
tmpZoom = ((Me.Width / OldWidth) * 100) - 2.5
If tmpZoom <= ZoomMin Then tmpZoom = ZoomMin
If tmpZoom >= ZoomMax Then tmpZoom = ZoomMax
If tmpZoom <= ZoomMin Or tmpZoom >= ZoomMax Then
If (CurStyle And WS_MAXIMIZE) = WS_MAXIMIZE Then
Me.Width = (tmpZoom * OldWidth) / 100
Me.Height = (Me.Width * OldHeight) / OldWidth
End If
End If
Me.Zoom = tmpZoom
End Sub