How to Position an Excel VBA UserForm Below a Button
Question details
The user needs to align an Excel VBA UserForm directly beneath a specific button rather than below a text box or in the center of the screen, which requires referencing the button's location and dimensions.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Developing a custom Excel macro interface where a UserForm must appear precisely below the clicked button for better user experience.
- Observed behavior
- The UserForm currently defaults to an incorrect location, requiring VBA code to dynamically reference the target button's coordinates and adjust the form's startup position.
Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have enabled the Developer tab in your ribbon to access the VBA Editor and object properties.
Use VBA Code to Calculate Button Coordinates
Set the UserForm's StartUpPosition to Manual and use VBA to calculate the Top and Left properties based on the target button.
To position a UserForm relative to an active button on a worksheet, you must change the UserForm's StartUpPosition to 0 (Manual). Because worksheet shapes use relative coordinates and UserForms use screen coordinates, you may need to use ActiveWindow properties to bridge the gap.
Press Alt + F11 to open the VBA Editor. Select your UserForm, open the Properties window (F4), and change the 'StartUpPosition' property to '0 - Manual'.
Double-click the button on your worksheet (in Design Mode) to open its Click event code in the VBA Editor.
Insert code to align the form. For basic alignment, use: UserForm1.Top = ActiveSheet.Shapes("Button 1").Top + ActiveSheet.Shapes("Button 1").Height. Then set UserForm1.Left = ActiveSheet.Shapes("Button 1").Left.
Add the command UserForm1.Show at the end of the script to display the form at your newly defined coordinates.

Consult Microsoft Q&A for Advanced Windows API Methods
For complex setups like multiple monitors, standard VBA might fall short. Microsoft Q&A offers expert help for integrating Windows API calls.
Experience Seamless VBA & Macro Support with WPS Office
Need to run complex VBA scripts and UserForms? WPS Office provides excellent compatibility with Microsoft Excel macros, allowing you to execute VBA code, create UserForms, and automate tasks efficiently without a heavy subscription.
- 1. Download and Install: Get WPS Office for free from the official website and install it on your device.
- 2. Open Macro Workbook: Open your existing .xlsm file in WPS Spreadsheet without losing any code.
- 3. Run UserForms: Navigate to the Developer tab to access the VBA Editor and execute your custom UserForms perfectly.

Frequently Asked Questions
Why does my VBA UserForm always appear in the center of the screen?
By default, an Excel UserForm's StartUpPosition property is set to 1 (CenterOwner) or 2 (CenterScreen). You must change this property to 0 (Manual) before you can apply custom Top and Left coordinates via VBA.
Can I position a UserForm exactly where the mouse clicks?
Yes, but you will need to utilize Windows API functions like GetCursorPos within your VBA module to capture the exact X and Y screen coordinates of the mouse click, and then assign those coordinates to the UserForm.
Why are my UserForm's Top and Left properties not aligning accurately with the button?
Worksheet shapes calculate their position relative to the worksheet canvas, while UserForms position themselves relative to the entire screen. To get perfect alignment, you must often account for the Ribbon height, application window position, and sheet zoom level using ActiveWindow properties.




