Workbook not closed when OnBeginShutdown and OnDisconnection events fire in Excel Addin


A

Alan

I have built a Shared Add-in project using Visual Studio 2003, VB.NET and
Framework 1.1.
It is designed to run in Excel. I modifed the wizard generated code to use
the Excel COM object model.
I added a COM reference to the Excel 11.0 object library. I then declared a
class instance-level variable of type Excel.Application, WithEvents. I then
printed out the Workbooks.Count in the OnBeginShutdown and OnDisconnection
events; and they both show a count of 1.

My goal is to check in the Excel file to a document management system when
the workbook closes, but the file is still in use and the DMS can't move it
from the local system.

Here is my code:

Imports Microsoft.Office.Core
Imports Extensibility
Imports System.Runtime.InteropServices
Imports MOI = Microsoft.Office.Interop

<GuidAttribute("61BEC854-3387-4B79-B9C4-BBE7AB328D5A"),
ProgIdAttribute("TestExcelAddin.Connect")> _
Public Class Connect

Implements Extensibility.IDTExtensibility2

Dim WithEvents applicationObject As MOI.Excel.Application
Dim addInInstance As Object

Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
System.Diagnostics.Debug.WriteLine("OnBeginShutdown: WorkBooks.Count
= " & applicationObject.Workbooks.Count)
End Sub

Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub

Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnStartupComplete
End Sub

Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnDisconnection
System.Diagnostics.Debug.WriteLine("OnDisconnection: WorkBooks.Count
= " & applicationObject.Workbooks.Count)
End Sub

Public Sub OnConnection(ByVal application As Object, ByVal connectMode
As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As
System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
applicationObject = application
addInInstance = addInInst
End Sub
End Class
 
Ad

Advertisements

P

pavan

Hey Alan,
I suppose, by the time the workbook close is called the addin execution
finishes. hence, it looks like a requirement that cant b fullfilled.

Regards,
Pavan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top