Visio2000: Sample Macro to Quit Microsoft Visio When a Drawing Is Closed (275516)



The information in this article applies to:

  • Microsoft Visio Professional 5.0
  • Microsoft Visio 2000 Enterprise Edition
  • Microsoft Visio 2000 Professional Edition
  • Microsoft Visio 2000 Standard Edition
  • Microsoft Visio 2000 Technical Edition

This article was previously published under Q275516

SUMMARY

This article contains a sample Microsoft Visual Basic for Applications macro (Sub procedure) to quit Microsoft Visio when you close a drawing.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following sample Visual Basic macro demonstrates how to quit Microsoft Visio when you close the drawing.

CAUTION: Do not use this example when multiple files are open. Visio prompts you to save changes in the active drawing only. You will not receive a subsequent prompt to save changes to other open drawings.
  1. In your current Visio project, press ALT+F11 to start the Visual Basic Editor.
  2. On the Insert menu, click Module.
  3. On the View menu, click Code, and then copy or paste the following code into the module:
Option Explicit
Dim WithEvents m_Visio As Visio.Application

Private Const WM_QUIT = &H12
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
 (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal _
 lParam As Long) As Long
Private Const STR_QUITMARKER = "DoQuitNOW"

Private Sub quitVisio()
    Dim lResult As Long
    Dim hWnd As Long
    
    hWnd = ThisDocument.Application.WindowHandle32
    lResult = PostMessage(hWnd, WM_QUIT, 0, 0)
    
    '   Allow Visio to pump the message queue.
    '
    DoEvents
End Sub

Private Sub Document_BeforeDocumentClose(ByVal doc As IVDocument)
    quitVisio
End Sub
				

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbdtacode kbhowto KB275516