VBA & Macro Problems

How to Reposition an Excel VBA CommandBar Popup Window

Adam DavisAdam Davis Oct 20, 2026 868 views

Question details

The user wants to set a specific screen position, such as the center of the window, for a built-in Excel VBA CommandBar popup window used for worksheet navigation.

How to Reposition an Excel VBA CommandBar Popup Window
Product
Microsoft Excel
Device & OS
not provided
Scenario
Navigating between numerous worksheets (30+) using a popup menu assigned to a Quick Access Toolbar button.
Observed behavior
The built-in CommandBars.ShowPopup method natively lacks reliable parameters to define specific screen coordinates, making it difficult to control the popup's screen position directly via VBA.
Before you start

Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have the Developer tab enabled to access the Visual Basic editor and insert UserForms.

Solution 1Recommended

Create a Centered Custom UserForm for Worksheet Navigation

Since Excel controls the built-in CommandBar popup position automatically, creating a custom UserForm with a ListBox provides precise control over its screen location and behavior.

The CommandBars.ShowPopup method natively lacks absolute coordinate positioning in VBA. It generally defaults to appearing where the macro was triggered, such as near the Quick Access Toolbar button.

A custom UserForm circumvents this limitation. By utilizing the StartUpPosition property, you can force the navigation menu to open precisely in the center of the application window, regardless of where the cursor is located.

1
Open the VBA Editor

Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.

2
Insert a New UserForm

Click 'Insert' in the top menu and select 'UserForm'. Using the Toolbox, draw a 'ListBox' control onto the new form to hold your worksheet names.

3
Set the Form to Center

Select the UserForm. In the Properties window on the left, locate the 'StartUpPosition' property and change it to '1 - CenterOwner'. This ensures it always opens in the middle of the Excel window.

4
Add Initialization Code

Right-click the UserForm and select 'View Code'. Use the 'UserForm_Initialize' event to loop through the workbook and populate the ListBox with the names of all visible worksheets.

5
Add Navigation Code

In the same code window, add code to the ListBox's 'Click' or 'DblClick' event to execute 'Worksheets(ListBox1.Value).Activate', followed by 'Unload Me' to close the form after selection.

Create a Centered Custom UserForm for Worksheet Navigation
Quick Access Toolbar Integration: You can still trigger this custom UserForm with a single click. Create a simple one-line macro containing 'UserForm1.Show' in a standard module, and assign that macro to a button on your Quick Access Toolbar.
Advanced VBA Support in WPS

Run VBA UserForms Seamlessly with WPS Office

WPS Office provides robust support for Excel VBA, allowing you to create, edit, and run custom UserForms and CommandBar macros just as you would in Microsoft Excel. It offers a familiar interface and comprehensive macro compatibility to streamline your workbook navigation.

  1. 1. Enable Developer Tools: Open your spreadsheet in WPS Office, navigate to the Options menu, and ensure the Developer tab is enabled.
  2. 2. Open the VB Editor: Click the Developer tab and select 'VB Editor' (or press ALT + F11) to access the integrated VBA coding environment.
  3. 3. Insert UserForms: Use the exact same VBA methods to insert UserForms, customize properties like StartUpPosition, and execute your navigation macros instantly.
Seamlessly execute Excel VBA scripts and custom UserForms100% compatibility with Microsoft Excel macro-enabled files (.xlsm)Familiar Developer tab interface for writing and debugging codeLightweight, fast, and completely free Office alternative
QA img-9

Frequently Asked Questions

Can I use Windows API to position CommandBars.ShowPopup?

While advanced users sometimes use Windows API functions like GetCursorPos or SetCursorPos to simulate cursor placement before calling ShowPopup, it is highly unstable across different display resolutions and scaling settings. A UserForm is much more reliable.

Why doesn't the CommandBar popup show exactly where I click?

By default, CommandBars.ShowPopup attempts to render at the current mouse cursor location. If you trigger the macro via a Quick Access Toolbar button, the popup will appear near the top-left of the screen rather than in the center of the sheet.

How do I assign my custom UserForm macro to a button?

First, write a simple subroutine in a standard module containing the command 'UserForm1.Show'. Then, right-click the Quick Access Toolbar, select 'Customize Quick Access Toolbar', choose 'Macros' from the dropdown, and add your new subroutine to the toolbar.