The AlertResponse property determines whether Visio will show alerts and modal dialog boxes to the user.
So by presetting the type of response we want, we can acept the dialog prompt with a desired response and nerver see it or have it hold up your automation.
If the AlertResponse property is 0 (its default value), alerts and modal dialog boxes are displayed.Code:Constant | Value
----------------
IDOK | 1
IDCANCEL | 2
IDABORT | 3
IDRETRY | 4
IDIGNORE | 5
IDYES | 6
IDNO | 7
Visio 2003 VBA Code Example:
VB Code:
Option Explicit 'Behind ThisDocument Private Sub Command1_Click() Dim lRet As Long 'Save alert response so we can revert it back to original setting lRet = Application.AlertResponse 'Tell it that we want to automatically choose "No" Application.AlertResponse = 7 'Close the document after some changes have been made 'No save prompt will be displayed since we told visio to choose the "No" button Application.ActiveDocument.Close 'Revert back to original setting Application.AlertResponse = lRet End Sub
Visio 2003 And VB 6 Code Example:
VB Code:
Option Explicit 'Add a reference to Microsoft Visio xx.0 Object Library Private Sub Command1_Click() Dim oApp As Visio.Application Dim oVsd As Visio.Document Dim lRet As Long 'Open the Visio File Set oApp = New Visio.Application Set oVsd = oApp.Documents.Open("C:\Development\Tips\Visio FAQ - Alert Response\Drawing1.vsd") oApp.Visible = True 'Save alert response so we can revert it back to original setting lRet = oApp.AlertResponse 'Tell it that we want to automatically choose "No" oApp.AlertResponse = 7 'Close the document after some changes have been made 'No save prompt will be displayed since we told visio to choose the "No" button oApp.ActiveDocument.Close 'Revert back to original setting oApp.AlertResponse = lRet End Sub
Visio 2003 And VB.NET 2003 Code Example:
VB Code:
[color=blue]Option [color=blue]Explicit On[/color] [color=blue]Option[/color] Strict On[/color] 'Add a reference to Microsoft Visio xx.0 Object Library from the References COM tab. [color=blue]Imports[/color] Visio = Microsoft.Office.Interop.Visio [color=blue]Public Class[/color] Form1 [color=blue]Inherits[/color] System.Windows.Forms.Form [color=DimGray]"Windows Form Designer generated code"[/color] [color=blue]Private[/color] oApp [color=blue]As[/color] Visio.Application [color=blue]Private[/color] oVsd [color=blue]As[/color] Visio.Document [color=blue]Private[/color] lRet [color=blue]As Short[/color] [color=blue]Private Sub[/color] btnOpen_Click([color=blue]ByVal[/color] sender [color=blue]As[/color] System.Object, [color=blue]ByVal[/color] e [color=blue]As[/color] System.EventArgs) [color=blue]Handles[/color] btnOpen.Click 'Open the Visio File oVsd = oApp.Documents.Open("C:\Development\Tips\Visio FAQ - Alert Response\Drawing1.vsd") oApp.Visible = [color=blue]True[/color] 'Save alert response so we can revert it back to original setting lRet = oApp.AlertResponse 'Tell it that we want to automatically choose "No" oApp.AlertResponse = 7 [color=blue]End [color=blue]Sub[/color] Private Sub[/color] btnClose_Click([color=blue]ByVal[/color] sender [color=blue]As[/color] System.Object, [color=blue]ByVal[/color] e [color=blue]As[/color] System.EventArgs) [color=blue]Handles[/color] btnClose.Click 'Close the document after some changes have been made oVsd.Pages.Add() 'Just to invoke a change in the drawing 'No save prompt will be displayed since we told visio to choose the "No" button oApp.ActiveDocument.Close() 'Revert back to original setting oApp.AlertResponse = lRet oVsd = [color=blue]Nothing[/color] oApp.Quit() oApp = [color=blue]Nothing End [color=blue]Sub[/color] Private Sub[/color] Form1_Load([color=blue]ByVal[/color] sender [color=blue]As[/color] System.Object, [color=blue]ByVal[/color] e [color=blue]As[/color] System.EventArgs) [color=blue]Handles[/color] MyBase.Load oApp = [color=blue]DirectCast[/color]([color=black]CreateObject[/color]("Visio.Application"), Visio.Application) oApp.Visible = [color=blue]False End [color=blue]Sub[/color] [color=blue]End[/color] Class[/color]
Visio 2003 And C# 2003 Code Example:
VB Code:
[color=blue]using[/color] System; [color=blue]using[/color] System.Drawing; [color=blue]using[/color] System.Collections; [color=blue]using[/color] System.ComponentModel; [color=blue]using[/color] System.Windows.Forms; [color=blue]using[/color] System.Data; [color=blue]using[/color] Visio = Microsoft.Office.Interop.Visio; [color=dimgray]///[/color][color=darkgreen]Add a reference to Microsoft Visio xx.0 [color=darkgreen]Object[/color] Library[/color] [color=blue]namespace[/color] FAQ_Visio___AlertResponse_CS { [color=blue]public class[/color] Form1 : System.Windows.Forms.Form { [color=blue]private[/color] System.Windows.Forms.Button btnOpen; [color=blue]private[/color] System.Windows.Forms.Button btnClose; [color=blue]private[/color] System.ComponentModel.Container components = [color=blue]null[/color]; [color=blue]private[/color] Visio.Application oApp; [color=blue]private[/color] Visio.Document oVsd; [color=blue]private short[/color] lRet; [color=blue]public[/color] Form1() { InitializeComponent(); } [color=blue]protected override void[/color] Dispose( [color=blue]bool[/color] disposing ) { [color=blue]if[/color]( disposing ) { [color=blue]if[/color] (components != [color=blue]null[/color]) { components.Dispose(); } } [color=blue]base[/color].Dispose( disposing ); } [color=dimgray]"Windows Form Designer generated code"[/color] [STAThread] [color=blue]static void[/color] Main() { Application.Run([color=blue]new[/color] Form1()); } [color=blue]private void[/color] Form1_Load([color=blue]object[/color] sender, System.EventArgs e) { oApp = [color=blue]new[/color] Visio.Application(); oApp.Visible = [color=blue]false[/color]; } [color=blue]private void[/color] btnOpen_Click([color=blue]object[/color] sender, System.EventArgs e) { [color=dimgray]///[/color][color=darkgreen]Open the Visio File[/color] oVsd = oApp.Documents.[color=black]Open[/color](@"C:\Development\Tips\Visio FAQ - Alert Response\Drawing1.vsd"); oApp.Visible = [color=blue]true[/color]; [color=dimgray]///[/color][color=darkgreen]Save alert response so we can revert it back to original setting[/color] lRet = oApp.AlertResponse; [color=dimgray]///[/color][color=darkgreen]Tell it that we want to automatically choose "No"[/color] oApp.AlertResponse = 7; } [color=blue]private void[/color] btnClose_Click([color=blue]object[/color] sender, System.EventArgs e) { [color=dimgray]///[/color][color=darkgreen]Close the document after some changes have been made[/color] oVsd.Pages.Add(); [color=dimgray]///[/color][color=darkgreen]Just to invoke a change in the drawing[/color] [color=dimgray]///[/color][color=darkgreen]No save prompt will be displayed since we told visio to choose the "No" button[/color] oApp.ActiveDocument.Close(); [color=dimgray]///[/color][color=darkgreen]Revert back to original setting[/color] oApp.AlertResponse = lRet; oVsd = [color=blue]null[/color]; oApp.Quit(); oApp = [color=blue]null[/color]; } } }
