logo
search
VBA & Macro Problems

How to Position an Excel VBA UserForm Below a Button

Khadija KhanKhadija Khan Oct 12, 2026 870 views

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.

How to Position an Excel VBA UserForm Below a Button
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.
Before you start

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.

Solution 1Recommended

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.

1
Set UserForm to Manual Position

Press Alt + F11 to open the VBA Editor. Select your UserForm, open the Properties window (F4), and change the 'StartUpPosition' property to '0 - Manual'.

2
Access Button Click Event

Double-click the button on your worksheet (in Design Mode) to open its Click event code in the VBA Editor.

3
Add Positioning Logic

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.

4
Show the UserForm

Add the command UserForm1.Show at the end of the script to display the form at your newly defined coordinates.

Use VBA Code to Calculate Button Coordinates
Screen vs. Worksheet Coordinates: If your Excel window is not maximized, the basic Top and Left properties might be misaligned. You may need to incorporate ActiveWindow.PointsToScreenPixelsY to account for the application window's exact screen position.
Free Microsoft Office alternative

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. 1. Download and Install: Get WPS Office for free from the official website and install it on your device.
  2. 2. Open Macro Workbook: Open your existing .xlsm file in WPS Spreadsheet without losing any code.
  3. 3. Run UserForms: Navigate to the Developer tab to access the VBA Editor and execute your custom UserForms perfectly.
Highly compatible with Microsoft Excel (.xlsm) macro-enabled formats.Lightweight and fast, opening large VBA-heavy workbooks in seconds.Familiar user interface makes migrating your VBA projects effortless.Free to download and use for your advanced data processing needs.
microsoft office alternative - wps office

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.