Modal versus Modeless Forms

Published on July 7, 2009

A modal form is any form that prevents your macro from continuing, and restricts interaction with the parent application, until the form is closed. A modeless (or nonmodal) form does not have these restrictions, allowing for other macro code to be executed as well as interaction with the parent application while the form is displayed.

There are two ways VBA allows you to control the modal state of a form. The first is via the form’s ShowModal property setting. A value of True will display the form as modal while a value of False will display the form as modeless. The other way to set the modal state is via your macro code. The form’s Show method takes an optional argument (either vbModal or vbModeless) that will override the form’s ShowModal property setting. The two methods are illustrated below.

Setting the Modal state in the form properties

Setting the Modal state in your macro code

‘Example for showing a form either as Modal or Modeless
Public Sub MyMacro()    
    'Typical method to show a form
    'Modal state uses the form’s ShowModal property
     UserForm1.Show

    'The following two methods override the form’s 
    'ShowModal property

    'Use this line to show a form as modal
     UserForm1.Show vbModal
    
    'Use this line to show a form as modeless
     UserForm1.Show vbModeless
End Sub

Tags:
Like this article? Share it!

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Privacy Policy