Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

OnDisconnection Method

Visual Studio .NET 2003

Occurs when an Add-in is unloaded from the environment.

[Visual Basic .NET]
Public Sub OnDisconnection( _
   ByVal RemoveMode As ext_DisconnectMode, _
   ByVal custom() As Variant _
[Visual Basic 6]
Sub OnDisconnection( _
   ByVal RemoveMode As ext_DisconnectMode, _
   ByVal custom() As Variant _
HRESULT __stdcall OnDisconnection(
   ext_DisconnectMode RemoveMode,
   SAFEARRAY** custom
void OnDisconnection(
   ext_DisconnectMode RemoveMode,
   object[] custom
[JScript .NET]
public function OnDisconnection(
   RemoveMode : ext_DisconnectMode,
   custom : Object[]


A ext_dm constant specifying how the Add-in was unloaded.
An array of Variant type values that provides additional data. This is not used by Visual Studio .NET.


OnDisconnection is a method that, when its host interface is implemented, acts as an event that occurs when an Add-in is unloaded.

An Add-in can be unloaded in any of the following ways:

  • Clearing the check box next to the Add-in in the Add-In Manager dialog box.
  • Closing its host application. If an Add-in is loaded and its host application closes, then the Add-in is unloaded. If the Add-in's load behavior is set to Startup, it is reloaded when the application starts again.
  • The Connect property of the corresponding AddIn object is set to False.

You can use the OnDisconnection event procedure to run code that restores any changes made to the application by the Add-in and to perform general clean-up operations.


Note that this code works only in an Add-In project, not in macros.

Imports Microsoft.Office.Core
imports Extensibility
imports System.Runtime.InteropServices
Imports EnvDTE

<GuidAttribute("B25D9733-A1B2-420D-8F6B-478E2B051C83"), ProgIdAttribute("MyAddin1.Connect")> _
Public Class Connect
   Implements Extensibility.IDTExtensibility2

   Dim applicationObject As EnvDTE.DTE
   Dim addInInstance as EnvDTE.AddIn
   Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
      Msgbox("Add-In disconnection event occuring.")
   End Sub
End Class

See Also

OnAddInsUpdate Method | OnBeginShutdown Method | OnConnection Method | OnStartupComplete Method

Applies To: IDTExtensibility2 Interface

© 2016 Microsoft