This Tutorial describes a method that you can use to extend the functionality or appearance of VBA UserForms and make it more user friendly at run time.
greetings and respect. Thanks for your great tutorials. I used this code, but considering that my Windows is 64-bit, it gives an error that the code must be updated (performance error). The code can be modified to automatically detect whether Windows is 32 or 64 .
@@mdshahparan1191 Option Explicit Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _ ByVal hWnd As LongPtr, ByVal nIndex As Long) As LongPtr Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _ ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr Private Declare PtrSafe Function FindWindowA Lib "user32" (ByVal lpClassName As String, _ ByVal lpWindowName As String) As LongPtr Private Const GWL_STYLE As Long = -16 Private Const WS_MINIMIZEBOX As Long = &H20000 Private Const WS_MAXIMIZEBOX As Long = &H10000 Private Sub UserForm_Activate() Dim hWnd As LongPtr Dim dwStyle As LongPtr ' Find the window handle of the UserForm hWnd = FindWindowA(vbNullString, Me.Caption) ' Get the current window style dwStyle = GetWindowLong(hWnd, GWL_STYLE) ' Add minimize and maximize buttons to the style dwStyle = dwStyle Or WS_MINIMIZEBOX dwStyle = dwStyle Or WS_MAXIMIZEBOX ' Set the modified style back to the window SetWindowLong hWnd, GWL_STYLE, dwStyle End Sub