Results 1 to 1 of 1

Thread: [FAQ's: OD] How do supress or automatically choose Alerts/Prompts in a drawing?

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    [FAQ's: OD] How do supress or automatically choose Alerts/Prompts in a drawing?

    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.

    Code:
    Constant | Value
    ----------------
    IDOK     |  1
    IDCANCEL |  2
    IDABORT  |  3
    IDRETRY  |  4
    IDIGNORE |  5
    IDYES    |  6
    IDNO     |  7
    If the AlertResponse property is 0 (its default value), alerts and modal dialog boxes are displayed.


    Visio 2003 VBA Code Example:

    VB Code:
    1. Option Explicit
    2. 'Behind ThisDocument
    3. Private Sub Command1_Click()
    4.  
    5.     Dim lRet As Long
    6.  
    7.     'Save alert response so we can revert it back to original setting
    8.     lRet = Application.AlertResponse
    9.     'Tell it that we want to automatically choose "No"
    10.     Application.AlertResponse = 7
    11.     'Close the document after some changes have been made
    12.     'No save prompt will be displayed since we told visio to choose the "No" button
    13.     Application.ActiveDocument.Close
    14.     'Revert back to original setting
    15.     Application.AlertResponse = lRet
    16.  
    17. End Sub

    Visio 2003 And VB 6 Code Example:
    VB Code:
    1. Option Explicit
    2. 'Add a reference to Microsoft Visio xx.0 Object Library
    3. Private Sub Command1_Click()
    4.  
    5.     Dim oApp As Visio.Application
    6.     Dim oVsd As Visio.Document
    7.     Dim lRet As Long
    8.  
    9.     'Open the Visio File
    10.     Set oApp = New Visio.Application
    11.     Set oVsd = oApp.Documents.Open("C:\Development\Tips\Visio FAQ - Alert Response\Drawing1.vsd")
    12.     oApp.Visible = True
    13.  
    14.     'Save alert response so we can revert it back to original setting
    15.     lRet = oApp.AlertResponse
    16.     'Tell it that we want to automatically choose "No"
    17.     oApp.AlertResponse = 7
    18.     'Close the document after some changes have been made
    19.     'No save prompt will be displayed since we told visio to choose the "No" button
    20.     oApp.ActiveDocument.Close
    21.     'Revert back to original setting
    22.     oApp.AlertResponse = lRet
    23.  
    24. End Sub

    Visio 2003 And VB.NET 2003 Code Example:
    VB Code:
    1. [color=blue]Option [color=blue]Explicit On[/color]
    2. [color=blue]Option[/color] Strict On[/color]
    3. 'Add a reference to Microsoft Visio xx.0 Object Library from the References COM tab.
    4. [color=blue]Imports[/color] Visio = Microsoft.Office.Interop.Visio
    5.  
    6. [color=blue]Public Class[/color] Form1
    7.  
    8.     [color=blue]Inherits[/color] System.Windows.Forms.Form
    9.  
    10.     [color=DimGray]"Windows Form Designer generated code"[/color]
    11.  
    12.     [color=blue]Private[/color] oApp [color=blue]As[/color] Visio.Application
    13.     [color=blue]Private[/color] oVsd [color=blue]As[/color] Visio.Document
    14.     [color=blue]Private[/color] lRet [color=blue]As Short[/color]
    15.  
    16.     [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
    17.         'Open the Visio File
    18.         oVsd = oApp.Documents.Open("C:\Development\Tips\Visio FAQ - Alert Response\Drawing1.vsd")
    19.         oApp.Visible = [color=blue]True[/color]
    20.         'Save alert response so we can revert it back to original setting
    21.         lRet = oApp.AlertResponse
    22.         'Tell it that we want to automatically choose "No"
    23.         oApp.AlertResponse = 7
    24.     [color=blue]End [color=blue]Sub[/color]
    25.  
    26.     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
    27.         'Close the document after some changes have been made
    28.         oVsd.Pages.Add()         'Just to invoke a change in the drawing
    29.         'No save prompt will be displayed since we told visio to choose the "No" button
    30.         oApp.ActiveDocument.Close()
    31.         'Revert back to original setting
    32.         oApp.AlertResponse = lRet
    33.         oVsd = [color=blue]Nothing[/color]
    34.         oApp.Quit()
    35.         oApp = [color=blue]Nothing
    36.     End [color=blue]Sub[/color]
    37.  
    38.     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
    39.         oApp = [color=blue]DirectCast[/color]([color=black]CreateObject[/color]("Visio.Application"), Visio.Application)
    40.         oApp.Visible = [color=blue]False
    41.     End [color=blue]Sub[/color]
    42.  
    43. [color=blue]End[/color] Class[/color]

    Visio 2003 And C# 2003 Code Example:
    VB Code:
    1. [color=blue]using[/color] System;
    2. [color=blue]using[/color] System.Drawing;
    3. [color=blue]using[/color] System.Collections;
    4. [color=blue]using[/color] System.ComponentModel;
    5. [color=blue]using[/color] System.Windows.Forms;
    6. [color=blue]using[/color] System.Data;
    7. [color=blue]using[/color] Visio = Microsoft.Office.Interop.Visio;
    8. [color=dimgray]///[/color][color=darkgreen]Add a reference to Microsoft Visio xx.0 [color=darkgreen]Object[/color] Library[/color]
    9. [color=blue]namespace[/color] FAQ_Visio___AlertResponse_CS
    10. {
    11.     [color=blue]public class[/color] Form1 : System.Windows.Forms.Form
    12.     {
    13.         [color=blue]private[/color] System.Windows.Forms.Button btnOpen;
    14.         [color=blue]private[/color] System.Windows.Forms.Button btnClose;
    15.         [color=blue]private[/color] System.ComponentModel.Container components = [color=blue]null[/color];
    16.         [color=blue]private[/color] Visio.Application oApp;
    17.         [color=blue]private[/color] Visio.Document oVsd;
    18.         [color=blue]private short[/color] lRet;
    19.  
    20.         [color=blue]public[/color] Form1()
    21.         {
    22.             InitializeComponent();
    23.         }
    24.         [color=blue]protected override void[/color] Dispose( [color=blue]bool[/color] disposing )
    25.         {
    26.             [color=blue]if[/color]( disposing )
    27.             {
    28.                 [color=blue]if[/color] (components != [color=blue]null[/color])
    29.                 {
    30.                     components.Dispose();
    31.                 }
    32.             }
    33.             [color=blue]base[/color].Dispose( disposing );
    34.         }
    35.  
    36.         [color=dimgray]"Windows Form Designer generated code"[/color]
    37.  
    38.         [STAThread]
    39.         [color=blue]static void[/color] Main()
    40.         {
    41.             Application.Run([color=blue]new[/color] Form1());
    42.         }
    43.         [color=blue]private void[/color] Form1_Load([color=blue]object[/color] sender, System.EventArgs e)
    44.         {
    45.             oApp = [color=blue]new[/color] Visio.Application();
    46.             oApp.Visible = [color=blue]false[/color];
    47.         }
    48.  
    49.         [color=blue]private void[/color] btnOpen_Click([color=blue]object[/color] sender, System.EventArgs e)
    50.         {
    51.             [color=dimgray]///[/color][color=darkgreen]Open the Visio File[/color]
    52.             oVsd = oApp.Documents.[color=black]Open[/color](@"C:\Development\Tips\Visio FAQ - Alert Response\Drawing1.vsd");
    53.             oApp.Visible = [color=blue]true[/color];
    54.             [color=dimgray]///[/color][color=darkgreen]Save alert response so we can revert it back to original setting[/color]
    55.             lRet = oApp.AlertResponse;
    56.             [color=dimgray]///[/color][color=darkgreen]Tell it that we want to automatically choose "No"[/color]
    57.             oApp.AlertResponse = 7;
    58.         }
    59.  
    60.         [color=blue]private void[/color] btnClose_Click([color=blue]object[/color] sender, System.EventArgs e)
    61.         {
    62.             [color=dimgray]///[/color][color=darkgreen]Close the document after some changes have been made[/color]
    63.             oVsd.Pages.Add(); [color=dimgray]///[/color][color=darkgreen]Just to invoke a change in the drawing[/color]
    64.             [color=dimgray]///[/color][color=darkgreen]No save prompt will be displayed since we told visio to choose the "No" button[/color]
    65.             oApp.ActiveDocument.Close();
    66.             [color=dimgray]///[/color][color=darkgreen]Revert back to original setting[/color]
    67.             oApp.AlertResponse = lRet;
    68.             oVsd = [color=blue]null[/color];
    69.             oApp.Quit();
    70.             oApp = [color=blue]null[/color];
    71.         }
    72.     }
    73. }
    Last edited by RobDog888; Aug 7th, 2006 at 04:42 AM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width