Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Specifying Location for a Message Box.
by Allen Wyatt
(last updated January 3, 2015)
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.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10030) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Specifying Location for a Message Box.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
It can be frustrating when you get error messages doing something that you previously did with no errors. If you get an out ...Discover More
Want to easily control which records get imported from a text file into Excel? It's easy to do when you write the macro that ...Discover More
Macros are great at working with text. This tip presents an example that shows this versatility by reversing the contents of ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.