Excel Application.WorkbookOpen breaks OLE to Word

Copper Contributor

I created and Excel addin in Visual Studio VB that seems to break OLE between Excel and Word. The problem is caused by a Application.WorkbookOpen sub in ThisAddIn.vb. Select an Excel range and paste it into Word as a Worksheet Object. It is now impossible to edit the Worksheet object and Word gives an "item cannot be found" error (see image). After a few minutes Excel gives an OLE Error (see image)

 Excel object error.jpgExcel OLE error.png

The problem can be recreated by starting a new Visual Studio Project using the "Excel VSTO Add-in" template. Add the Application.WorkbookOpen sub to ThisAddIn.vb (see code) and run the add-in. 


Public Class ThisAddIn
    Private Sub ThisAddIn_Startup() Handles Me.Startup
    End Sub
    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
    End Sub
    Private Sub Application_WorkbookOpen(Wb As Workbook) Handles Application.WorkbookOpen
    End Sub
End Class


 Is this a bug or am I doing something wrong?

0 Replies