![ups api vba ups api vba](https://cdn2.f-cdn.com/files/download/74470535/f14bfc.jpg)
To capture the initial bottom and right positions of the ListBox and Button, we set up some Private variables to hold the values.
Ups api vba code#
The code below must be included within the UserForm’s code module to function correctly. Provided we keep the same distance from the bottom and right it will appear that these items are moving in sync with the UserForm. To enable this to happen we need to know the position of these objects from the bottom and right of the UserForm. lstListBox should change in size, but not in position while the cmdClose will change in position but not in size. To illustrate the process, I’ve created a UserForm which looks like this:īoth of these elements should change when then UserForm resizes. Just replace myUserForm with the name of your form, or use Me if within the UserForm’s code module. To turn off resizing, use the following Call ResizeWindowSettings(myUserForm, False)
![ups api vba ups api vba](https://i.stack.imgur.com/1Y0kQ.png)
Anytime we want to turn on resizing for a UserForm, use the following: Call ResizeWindowSettings(myUserForm, True) The two code segments above create a reusable procedure which we can use to toggle the UserForm’s resize setting on or off. 'Recreate the UserForm window with the new style SetWindowLong windowHandle, GWL_STYLE, windowStyle WindowStyle = windowStyle + (WS_THICKFRAME) WindowStyle = windowStyle And (Not WS_THICKFRAME) 'Determine the style to apply based If show = False Then WindowStyle = GetWindowLong(windowHandle, GWL_STYLE) WindowHandle = FindWindowA(vbNullString, frm.Caption)
Ups api vba windows#
Sub ResizeWindowSettings(frm As Object, show As Boolean)ĭim windowStyle As Long Dim windowHandle As Long 'Get the references to window and style position within the Windows memory 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.
![ups api vba ups api vba](https://i.stack.imgur.com/7hJv5.jpg)
Remember, Windows API codes will only work on Windows.
Ups api 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.
![ups api vba ups api vba](https://www.automateexcel.com/excel/wp-content/uploads/2020/07/PIC-01.png)
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.