I'm writing a class that utilizes the Microsoft.Office.Interop.Excel assembly. It's a part of a "one stop shop" DLL library which will be utilized in a java solution (to limit the amount of interfacing on java side).
I am getting the following error:
Additional information: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Excel.Worksheets'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208B1-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
This is thrown by the following code:
Public Class XL
Public XL As Excel.Application = Nothing
Public XLN As String
Public WBS As Excel.Workbooks = Nothing
Public WBSN() As String
Public WB As Excel._Workbook = Nothing
Public WBN As String
Public WSS As Excel.Worksheets = Nothing
Public WSSN() As String
Public WS As Excel._Worksheet = Nothing
Public WSN As String
Public XLCelllValue As Object = Nothing
Public Sub New()
XL = New Excel.Application()
XL.Visible = True
WBS = XL.Workbooks
WB = WBS.Add()
WSS = WB.Worksheets '<this is the line that throws the exception
WS = WSS(1)
End Sub
End Class
I'm not sure what I'm doing wrong All properties are declared as public, Worksheets is a valid collection the WB property type is Excel._workbook and the WSS Property type is Excel.worksheets.
Any ideas what I'm missing?