RawlinsCross
Active Member
- Joined
- Sep 9, 2016
- Messages
- 437
I have found an code snippit that describes resizing a userform (without resizing the controls) but it seems not to work when you run it on 64-bit systems. I'm getting a compile error (see below)
VBA Code:
'Written: February 14, 2011
'Author: Leith Ross
'
'NOTE: This code should be executed within the UserForm_Activate() event.
' John note: This code plays around with the API in order to size userforms
#If VBA7 Then
Private Declare PtrSafe Function GetForegroundWindow Lib "user32.dll" () As LongPtr
Private Declare PtrSafe Function GetWindowLong _
Lib "user32.dll" _
(ByVal hWnd As LongPtr, _
ByVal nIndex As LongPtr) _
As LongPtr
Private Declare PtrSafe Function SetWindowLong _
Lib "user32.dll" _
(ByVal hWnd As LongPtr, _
ByVal nIndex As LongPtr, _
ByVal dwNewLongPtr As LongPtr) _
As LongPtr
Private Const WS_THICKFRAME As LongPtr = &H40000
Private Const GWL_STYLE As LongPtr = -16
#Else
Private Declare PtrSafe Function GetForegroundWindow Lib "user32.dll" () As Long
Private Declare PtrSafe Function GetWindowLong _
Lib "user32.dll" Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) _
As Long
Private Declare PtrSafe Function SetWindowLong _
Lib "user32.dll" Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) _
As Long
Private Const WS_THICKFRAME As Long = &H40000
Private Const GWL_STYLE As Long = -16
#End If
Public Sub MakeFormResizable()
Dim lStyle As Long
Dim hWnd As Long
Dim RetVal
hWnd = GetForegroundWindow '<- Compile Error Type Mismatch
'Get the basic window style
lStyle = GetWindowLong(hWnd, GWL_STYLE) Or WS_THICKFRAME
'Set the basic window styles
RetVal = SetWindowLong(hWnd, GWL_STYLE, lStyle)
End Sub