Written by Allen Wyatt (last updated August 28, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021
Leonard wonders if, when displaying a message box in a macro, there is a way to force the box to appear at a specific location on the screen.
There is no way to do this, as the MsgBox function doesn't include any way to specify a location. Instead, Excel displays the message box centered on the screen. If you need the capability to position the box, then the easiest solution is to rely upon the InputBox function. Unlike MsgBox, InputBox includes option parameters for specifying a location. Here's an example:
sName = InputBox(Prompt:="Enter your name", XPos:=2880, YPos:=1440)
Note that you can specify both an X position and a Y position for the upper-left corner of the box. The values assigned to these parameters are measured from the top-left corner of the screen, and are specified in twips. (There are 1440 twips to an inch.)
An input box does, of course, expect the user to provide input, whereas a message box does not. If you don't want to potentially confuse your users by soliciting input when none is really needed, then you'll need to create a UserForm to simulate a message box.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10030) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021. You can find a version of this tip for the older menu interface of Excel here: Specifying Location for a Message Box.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
Macros are often used to process the data in a worksheet. If that data includes dates that need to be processed, you'll ...
Discover MoreThe Text-to-Columns tool is an extremely powerful feature that allows you to divide data in a variety of ways. Excel even ...
Discover MoreIf you create a user form in VBA that includes checkboxes, you may want to make the checkboxes larger. You can't adjust ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2025-06-25 10:39:56
J. Woolley
Re. my previous comment below, consider the following MsgBox related procedures available in My Excel Toolbox:
Sub MsgBoxCustom(Result, Prompt, [Buttons], [Title], [Helpfile],
[Context], [XY])
Sub MsgBoxCustom_Set(ButtonID, [Label])
Sub MsgBoxCustom_Reset(ButtonID)
Function MsgBox_Custom(Prompt, [Buttons], [Title], [Helpfile],
[Context], [XY])
MsgBoxCustom displays a standard modal MsgBox with optional custom button labels and/or custom position. The result from MsgBox is returned in Result. The remaining arguments except XY are passed directly to MsgBox. Optional XY is used to position the MsgBox dialog. If XY is a Range, it will be made visible and the top-left corner of MsgBox will match the Range's top-left corner. If XY is an array, its first two values define the X-Y (left-top) screen coordinates of the MsgBox dialog's corner in pixels.
MsgBoxCustom_Set and MsgBoxCustom_Reset can be used to set or reset custom MsgBox button labels; for example, "Quit" could replace the "Cancel" button. MsgBox_Custom simply calls MsgBoxCustom and returns Result.
Sub MsgBoxModeless(Prompt, [Button], [Title], [Font], [NextProc],
[ButtonTip], [XY])
MsgBoxModeless displays a persistent non-modal UserForm with Prompt in a TextBox; a single CommandButton is included to close the UserForm. The button's label (Button) and font (Font) can be customized. NextProc specifies a macro to run after the button is clicked. ButtonTip is a ToolTip for the button. Default values are "Continue" for Button, "MsgBoxModeless" for Title, and null text ("") for NextProc and ButtonTip. When NextProc is null, the UserForm simply closes when the button is clicked. As with MsgBoxCustom, the last argument (XY) can be a worksheet's cell or absolute screen coordinates to position the UserForm; otherwise, its standard position (centered) applies. MsgBoxModeless returns immediately after showing the UserForm, which runs independently.
See https://sites.google.com/view/MyExcelToolbox/
2025-06-23 14:51:33
J. Woolley
If you are interested in InputBox, consider the following procedures available in My Excel Toolbox:
Function InputBoxVBA_Custom(Prompt, [Title], [Default], [Xpos], [Ypos],
[HelpFile], [Context], [Target])
Function InputBoxApp_Custom(Prompt, [Title], [Default], [Left], [Top],
[HelpFile], [Context], [Type], [Target])
InputBoxVBA_Custom displays a standard modal VBA InputBox with optional custom position and returns the result. All arguments except Target match those of VBA's InputBox function, which limits Prompt to approximately 1,024 characters. If Target is omitted and both Xpos and Ypos are supplied, they specify the top-left corner of the dialog in twips. If Target is omitted and either Xpos or Ypos is omitted, the dialog will be centered (X) and down about one-third (Y). If Target is supplied it must be a cell range; in this case, Target will be made visible and the InputBox's top-left corner will match the top-left corner of Target (overriding Xpos/Ypos). If Target's workbook is not open, an error will occur.
InputBoxApp_Custom calls Excel's non-modal Application.InputBox method with optional custom position and returns the result. All arguments except Target match those of Application.InputBox and are similar to VBA's InputBox with the addition of Type (data type), but Application.InputBox limits Prompt to 255 characters and ignores Left/Top preferring its most recent position. If Target is supplied it must be a cell range; in this case, Target will be made visible and the InputBox's top-left corner will match the top-left corner of Target. If Target's workbook is not open, an error will occur.
See https://sites.google.com/view/MyExcelToolbox/
2022-04-20 15:02:47
improveyourcoding
thx
2021-09-05 07:24:21
Jim Comin
Regarding location of message boxes, I was trying to figure out how to change the location, when thankfully I checked in with you and found that you can't.
You can, however, drag them around once opened. I had just created one that is right smack in the way of the users work, so I just added a notation in the message box that says, "you can drag it out of the way if it is interfering with your view."
2021-08-28 10:11:25
J. Woolley
My Excel Toolbox includes Sub MsgBoxCustom and Function MsgBox_Custom, which display a standard MsgBox with custom position and/or button labels. The custom position can be absolute screen coordinates or relative to a cell.
My Excel Toolbox also includes Function InputBoxVBA_Custom and Function InputBoxApp_Custom with screen coordinate or cell-relative positioning.
See https://sites.google.com/view/MyExcelToolbox/
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments