This following code must be included within the same module as the code above but does not need to be directly below it. Lib "user32" ( ByVal hWnd As Long) As Long Public Declare Function FindWindowA _ # Else Public Declare Function GetWindowLong _īyVal hWnd As Long, ByVal nIndex As Long) As Long Public Declare Function SetWindowLong _īyVal dwNewLong As Long) As Long Public Declare Function DrawMenuBar _ Lib "user32" ( ByVal lpClassName As String, _ Lib "user32" ( ByVal hWnd As Long) As Long Public Declare PtrSafe Function FindWindowA _ # If VBA7 Then Public Declare PtrSafe Function GetWindowLong _īyVal hWnd As Long, ByVal nIndex As Long) As Long Public Declare PtrSafe Function SetWindowLong _īyVal hWnd As Long, ByVal nIndex As Long, _īyVal dwNewLong As Long) As Long Public Declare PtrSafe Function DrawMenuBar _ It must be included at the top of the module before any functions or subprocedures, but below the Option Explicit statement (if there is one).
Setting up the Windows API codeĬopy the following code into a new standard module.
#Offset resize excel vba full#
The topic of Windows API codes is too big to discuss here, but by following the instructions below you can still get the code working, even if you don’t have a full understanding of why it works. Windows API codes make use of special functions which are not part of Excel or VBA, but part of the main Windows application. If your code is expected to work on Windows and Mac, then using the VBA solution is the better option. Of the two, the Windows API solution has a smoother, more integrated feel for the user, but it will only work on Windows. There are two solutions presented below, a Windows API method and a VBA only method. With a bit of coding magic, we can achieve a similar resizing effect for our VBA UserForms. Most other forms and windows within the Excel and Windows environments do not have a fixed sized they can be resized by the user. When creating a VBA UserForm, we generally set it to a specific size.