Making Modal Dialog Boxes Appear in Front of Workbooks

by Allen Wyatt
(last updated May 23, 2020)


Don tends to work on two monitors and have multiple workbooks open on the same instance of Excel. He also maximizes his windows. (He describes himself as a "see everything in one shot" type of guy.) Recently, when Don has done something that opens a modal dialog box, the box opens behind the workbook, which stops him from seeing the dialog box or interacting with it. He wonders if there is a way he can get the modal dialog boxes to appear in front of the workbook.

Before answering, it should be pointed out that dialog boxes can be of two types: modal and modeless. A modeless dialog box is one that is virtually independent of the program to which it belongs. A good example of such a dialog box is the Find and Replace dialog box. On the other hand, a modal dialog box (the ones that Don is having problems with) must be responded to or closed before you can continue working with the program to which the dialog box belongs.

It is unclear whether Don's problem is with modal dialog boxes generated by Excel itself or if they are dialog boxes generated by macros over which Don has control. If it is the former, then there is very little that can be done; the layered location of the dialog box is controlled entirely by the program (and the programmers that created it). In other words, it would take a code change to make the dialog box appeared layered on top of the workbook instead of under it.

Understand that there is a scenario in which the problem may not be due to an Excel programming problem. It could be that you have a third-party application running on the system which affects the layering of dialog boxes and their parent windows. The typical culprits in this scenario are memory-resident utilities that force themselves to always appear on top of whatever else is on the screen. The only way to see if this is the culprit is to disable the loading of such utilities and, within Excel, display a modal dialog box. If the behavior returns to normal, you then know the source of the problem.

If it is the case, however, that the dialog box is generated by a macro Don developed then the solution is to adjust the code that generates the modal dialog box. (In Excel macros these types of dialog boxes are typically implemented through userforms.).

The problem with userform placement in multiple screen scenarios is overcome by the manual placement of the userform within its initiating code. For instance, you can use some variation on this:

Load UserForm1
UserForm1.StartUpPosition = 0
UserForm1.Top = Application.Top + 25
UserForm1.Left = Application.Left + 25

You may need to experiment with the placement but setting the StartUpPosition property to 0 is required so that VBA knows you want to manually location the userform.


If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13349) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...


Deleting Conditional Formatting

After you've applied a conditional format to a cell, you may have a need to later delete that format so that the cell is ...

Discover More

Inconsistent Behavior of Find and Replace Dialog Box

The Find and Replace feature in Excel is one of the workhorse editing tools you can use. When the Find and Replace dialog ...

Discover More

Printing via Macro without Messages

When you are printing a document, it is not unusual to see messages (dialog boxes) periodically. When you want the ...

Discover More

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!

More ExcelTips (ribbon)

Removing All Macros

Macros are stored as part of a workbook so that they are always available when you have the workbook open. If you want to ...

Discover More

Delimited Text-to-Columns in a Macro

The Text-to-Columns tool is an extremely powerful feature that allows you to divide data in a variety of ways. Excel even ...

Discover More

Copying Named Ranges

Named ranges are a great tool to use in developing formula-heavy workbooks. You may want, at some point, to copy your ...

Discover More

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 4 + 0?

2020-09-23 02:57:02

Mike Fairley

Thanks J Woollley. They are all great suggestions, I will try them out and let you know how it works. I am learning a lot!

BTW - We have been struggling with this for more than a year for a large client. The dialog behaviour is very unpredictable. On some devices/version of Excel it is fine, and others not. I have a computer where it *always* goes to the back.

2020-09-22 15:59:28

J. Woolley

@Mike Fairley
I believe my previous suggestion will not work for this case. When I test your code with my configuration (after adjusting your oApp/olApp variables), the address book always appears in the foreground. I even tested calling your code from a UserForm, which you implied in your original question. Since the address book does not appear in the foreground for your configuration, try adding the following lines before and after the With... section:

Application.WindowState = xlMinimized
With oDialog
End With
Application.WindowState = xlNormal

If your code is called from a UserForm, try changing the form's ShowModal property to False. If that fails, try calling your code from a standard module and passing the results to your form's code.
If you cannot resolve the issue, this would be a good question for wellsr VBA Q&A:
You might also be interested in My Excel Toolbox:

2020-09-22 06:28:29

Mike Fairley

Thanks J Wooley, appreciate your suggestion. I am not sure where to put your code.

Sub AddressBookName()

Dim oApp As Outlook.Application
Dim oDialog As SelectNamesDialog
Dim oGAL As AddressList
Dim myAddrEntry As AddressEntry
Dim exchUser As Outlook.ExchangeUser

Dim AliasName As String
Dim FirstName As String
Dim LastName As String
Dim EmailAddress As String

Set oApp = CreateObject("Outlook.Application")
Application.Wait (Now + TimeValue("0:00:05"))
Set oDialog = olApp.Session.GetSelectNamesDialog
Set oGAL = olApp.GetNamespace("MAPI").AddressLists("Global Address List")

With oDialog
.AllowMultipleSelection = False
.InitialAddressList = oGAL
.ShowOnlyInitialAddressList = True
If .Display Then
--------------'this is the point where the Outlook dialog is displayed ---------------
AliasName = oDialog.Recipients.Item(1).Name
Set myAddrEntry = oGAL.AddressEntries(AliasName)
Set exchUser = myAddrEntry.GetExchangeUser

If Not exchUser Is Nothing Then
FirstName = exchUser.FirstName
LastName = exchUser.LastName
EmailAddress = exchUser.PrimarySmtpAddress
End If
End If
End With

Set olApp = Nothing
Set oDialog = Nothing
Set oGAL = Nothing
Set myAddrEntry = Nothing
Set exchUser = Nothing
End Sub

2020-09-21 10:41:15

J. Woolley

@Mike Fairley
You can try adding this line to your VBA after opening OAB:
CreateObject("WScript.Shell").AppActivate sOAB
where sOAB is a String identifying all or part of the OAB's titlebar caption. For example:
sOAB = "Address Book"

2020-09-20 22:13:06

Mike Fairley

Hi Allen. Love your work. Your site is my "goto" for Excel queries.

I have a related issue. When I call the Outlook Address Book from an Excel VBA form. The OAB always goes behind the Excel application. Any ideas how to resolve??

This Site

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.

Newest Tips

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.