This documentation is archived and is not being maintained.

Preventing Alerts and Dialog Boxes in Visio 2002

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
 

Microsoft Corporation

September 2001

Applies to:
   Microsoft Visio Standard 2002
   Microsoft Visio Professional 2002

Summary: This article discusses using the AlertResponse property to prevent Visio alerts and dialog boxes from appearing in your solutions. (3 printed pages)

Contents

Introduction
Preventing Alerts and Dialog Boxes
Setting the Value of the AlertResponse Property
Additional Information

Introduction

Certain operations, such as closing a document with unsaved modifications or deleting a shape that's protected from deletion, cause Microsoft® Visio® to display an alert or modal dialog box requesting the user to supply a response such as OK, Yes, No, or Cancel.

You can prevent Visio alerts and dialog boxes from appearing using the AlertResponse property. When you prevent alerts and dialog boxes from appearing, you can also set the value of the AlertResponse property to the default response for a dialog box. Visio won't display alerts or dialog boxes, and will behave as if the user had responded to the alert or dialog box with the value of the AlertResponse property.

Note:   You cannot prevent dialog boxes from appearing by using the ShapeSheet® window.

Preventing Alerts and Dialog Boxes

The following example demonstrates creating a macro that prevents alerts and dialog boxes from appearing for a specific document and behaves as if the user responded with OK. It also demonstrates creating another macro that resets the value of the AlertResponse property to its default value (0).

To prevent a dialog box from appearing while working in a specific document

  1. On the Tools menu, point to Macros, and then click Visual Basic Editor.
  2. In the Project window, double-click ThisDocument.
  3. In the ThisDocument code window, create the following macro to prevent alerts and dialog boxes from appearing, and then click OK.
    Public Sub PreventDialogs()
    Application.AlertResponse = IDOK
    End Sub
    
  4. In the ThisDocument code window, create the following macro to enable alerts and dialog boxes again for the document.
    Public Sub EnableDialogs()
    Application.AlertResponse = 0
    End Sub
    
  5. Close the Visual Basic Editor.
  6. Now, run the PreventDialogs macro, point to any Visio menu, and then click a command. The Visio dialog box for the command doesn't appear. To enable dialog boxes again, run the EnableDialogs macro. Visio alerts and dialog boxes will appear again.
    Note:    In real code, you should query and store the initial value of the AlertResponse property before changing the value. Then when you're ready to restore the value of the AlertResponse property, restore it to the stored value.

Setting the Value of the AlertResponse Property

The following table covers the constants and values for the AlertResponse property.

Table 1 AlertResponse Values

ConstantValue
IDOK1
IDCANCEL2
IDABORT3
IDRETRY4
IDIGNORE5
IDYES6
IDNO7

Additional Information

For more information about the AlertResponse property and the different values you can set for it, search for alert response in the Microsoft Visio 2002 online Help (on the Help menu, click Developer Reference).

Show: