A VBA MsgBox has no built-in argument for setting its screen coordinates. In Excel for Microsoft 365 on Windows, it is shown as a modal dialog associated with Excel, and Windows determines its exact placement—often near the center of the Excel window rather than at a position you can specify in the call.
How VBA decides where a MsgBox appears
The MsgBox function accepts a prompt, optional button and icon settings, and an optional title. It does not accept left, top, X, or Y coordinates. For example, adding a title or changing the buttons changes the dialog’s content and appearance, not its location.
On Windows, a message box is a dialog owned by the application that displays it. The operating system manages the dialog’s placement in relation to that owner and the current window arrangement. Consequently, the box may look screen-centered when Excel fills the monitor, but appear off-center relative to the physical display when Excel is restored, moved, or positioned on a secondary monitor. The exact result can also depend on the operating system and the way the application is activated.
This is why two people can run the same macro and see the message in different places. The macro has not necessarily changed: Excel’s window size and location, monitor arrangement, scaling, and dialog-management behavior can all affect what the person sees.
What the MsgBox arguments can and cannot change
The basic syntax lets you control the prompt, buttons, icon, default button, and title. Those choices are useful for communicating clearly and collecting a simple response, but none is a positioning option. For example, vbQuestion selects an icon, while vbYesNo selects buttons; neither tells Windows where to put the dialog.
This small example shows a conventional message box and stores the user’s response. It deliberately does not attempt to set a location:
Sub AskBeforeContinuing()
' Save a copy of the workbook before running macros.
Dim answer As VbMsgBoxResult
answer = MsgBox("Ready to continue?", _
vbYesNo + vbQuestion + vbDefaultButton2, _
"Confirmation")
If answer = vbYes Then
MsgBox "Continuing now.", vbInformation, "Status"
End If
End Sub
The first message uses the second button as the default selection. The second message appears only if the user chooses Yes. Neither message has a supported position setting. The code is illustrative; add your own safe action where appropriate, and save a separate copy of a workbook before running a macro. VBA macros can make changes that Ctrl+Z cannot undo.
Why it may look off-center
“Center of the screen” is not always a useful description on a computer with more than one display. Excel may be on a monitor to the left or right of the primary display, and a dialog associated with Excel may appear in relation to Excel’s window rather than at the center of the combined desktop. If Excel is not maximized, its center and the monitor’s center are different points.
Other factors can make the placement seem unexpected:
- Excel’s window state: A restored or partially covered Excel window has a different center from a maximized window.
- Multiple monitors: Moving Excel to another display can change where an owned dialog appears. Display arrangement and scaling may affect the visible result.
- Modal behavior: A modal message box blocks interaction with its owner until the user responds. Its relationship to that owner matters more than a fixed coordinate in your worksheet.
- Activation and timing: A message raised while another window has focus, or from an event that changes windows, may not appear where the user expects.
These are reasons to test a workflow with the same kind of window arrangement users have, not evidence that a worksheet cell controls the message box. A cell’s position, the active selection, and the location of a shape do not set a MsgBox coordinate.
Can you move a MsgBox with VBA?
Not through the documented MsgBox function. There is no supported parameter such as Left or Top, and changing the prompt text or title will not move it predictably. Windows API techniques can sometimes locate and reposition a native dialog, but they rely on operating-system window handles and timing. They are more fragile than ordinary VBA, can behave differently across Office bitness or Windows configurations, and do not provide a portable Excel solution.
For a workbook intended for other people, avoid building a critical workflow around a message box being at a precise coordinate. A dialog moved with low-level Windows calls can be misplaced if the window is not found, if the display arrangement changes, or if another dialog is active. Windows-specific API code is also not a cross-platform answer for Excel on Mac. If precise placement is essential, create a form that you control instead.
Use a UserForm when placement matters
An Excel VBA UserForm is the practical alternative when a prompt needs a consistent layout, additional instructions, custom buttons, or deliberate positioning. In the Visual Basic Editor, insert a form with Insert > UserForm, then configure its properties. Its StartUpPosition property offers built-in choices: 0 for manual positioning, 1 for centering over its owner, 2 for centering on the screen, and 3 for the Windows default.
For example, if a form named UserForm1 should request a screen-centered starting position, the calling procedure can set the property before displaying it:
Sub ShowCenteredForm()
' Save a copy of the workbook before running macros.
UserForm1.StartUpPosition = 2
UserForm1.Show
End Sub
This positions a UserForm according to its startup setting; it does not change where ordinary MsgBox calls appear. If you choose manual positioning, set the form’s Left and Top properties after setting StartUpPosition to 0. Those measurements and the behavior on multiple monitors should be checked in the actual environment, since a position suitable for one screen may be unsuitable on another.
A UserForm also takes more setup than a one-line message. You must design the controls, decide how buttons close the form, and handle the user’s choice in VBA. That effort is worthwhile for a repeated or important interaction, but unnecessary for a short informational alert whose default placement is acceptable.
Choosing between MsgBox and a UserForm
Choose MsgBox when you need a brief notice or a simple choice such as Yes, No, or Cancel. It is quick to write, familiar to users, and managed by the host application. It is a poor fit when the user must enter several values, see a persistent panel, or interact with worksheet content while the prompt remains visible.
Choose a UserForm when the layout itself is part of the task. It can contain labels, text boxes, lists, and buttons, and you can decide whether it is modal or modeless. A modal form blocks interaction with Excel until it is dismissed; a modeless form can remain open while the user works elsewhere. Modeless forms need additional care because the worksheet can change while the form is open.
For a simple message that should appear close to a particular worksheet control, another option is to display guidance on the sheet itself: for example, a clearly labeled cell, a shape, or a data-validation input message. These are not interchangeable with a modal warning, but they avoid implying that a message box can be anchored to a cell.
Common misconceptions and troubleshooting
A frequent misconception is that the optional buttons argument controls position. It does not: it selects button and icon constants, and may specify which button is the default. Likewise, a message box’s title argument changes its caption, not its owner or coordinates.
If a box appears behind another window or seems to be on the wrong display, first check where Excel is located, whether Excel is minimized or restored, and which window is active when the macro runs. Simplify the macro so the message appears directly from a normal procedure; event code and other automation can introduce additional windows or timing that complicates diagnosis. Also check whether another dialog is already open. A modal dialog prevents normal interaction with its owner, so multiple overlapping prompts can be confusing.
For users on Mac, the same key limitation applies: VBA’s MsgBox call has no coordinate arguments. The dialog is presented by the host operating system, and Windows-specific API approaches should not be assumed to work on Mac. If placement is a requirement, use a UserForm and verify its behavior in the version and display setup that matters to your audience.
Frequently Asked Questions
Can I specify the X and Y position of a VBA MsgBox?
No. The built-in MsgBox function has no X/Y or left/top arguments. Use a UserForm if you need control over the starting position.
Does MsgBox appear in the center of the screen or Excel?
There is no coordinate guarantee in the VBA call. On Windows it is an application-owned dialog, and it commonly appears in relation to the Excel window. The visible position depends on the window and display setup.
Can I center a VBA UserForm on the screen?
Yes. Set its StartUpPosition property to 2 before showing it to request screen centering. Test the result on the target setup, especially when multiple monitors are involved.
Will changing the active cell move a MsgBox?
No. Selecting a cell, scrolling the worksheet, or selecting a shape does not set the message box’s screen position.
Does this work differently in Excel for Mac?
The standard MsgBox function still has no position argument. Windows API techniques for moving native dialogs are Windows-specific, so do not rely on them for Mac; consider a UserForm and check its behavior on the intended platform.
Related
- Microsoft Excel Group Rows: How It Works and When to Use It
- Microsoft Excel Corrupt File? How to Repair It
- Microsoft Excel Find Circular References: A Clear Guide
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Optimize Copy-Paste Formulas in VBATo optimize formula copying in Excel VBA, assign a formula to an entire destination range at once instead…
- Macro Recorder for Windows: Options and How to ChooseA macro recorder for Windows captures repeated actions and replays them, but Windows does not provide one universal…
- Excel VBA Lookup: Find Matching Data with CodeAn Excel VBA lookup searches a range for a value and returns related information, such as a product…
- VBA Copy Paste Formats: Methods and ExamplesIn Excel VBA, copy formatting without changing cell contents by copying a source range and pasting with Paste:=xlPasteFormats.…
- VBA Error Handling in Loops: Safe Patterns That WorkIn VBA, use an error handler to decide what a loop should do when one item fails: log…
- Excel VBA Programming: What It Is and How to Use ItExcel VBA programming means using Visual Basic for Applications, Excel’s built-in programming language, to automate workbook tasks and…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.