I am trying to write an application using vb.net on VS 2017 to open and edit an Excel document for use on many computers of varying Windows versions (7, 8, 10 etc) and Microsoft Office installations (2010,'13 etc). I am writing this application on a Windows 7 computer, and my office version is 2010. However, when I run the code I get this error message:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Excel.Workbooks'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208DB-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
The following is my code:
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim GlobalProjectLoc As String
Dim FileLoc As String
Dim excelApp As Excel.Application
Dim excelWB As Excel.Workbooks
Dim excelWS As Excel.Worksheet
Private Sub btnSearch_Click_1(sender As Object, e As EventArgs) Handles btnSearch.Click
GlobalProjectLoc = "C:\Users\Documents\VBA\"
FileLoc = GlobalProjectLoc & "Excel File to Edit"
excelApp = New Excel.Application
excelWB = excelApp.Workbooks.Open(FileLoc)
End Sub
End Class
I have added both the Microsoft Office 14.0 Object Library
and Microsoft Excel 14.0 Object Library
to my references. I have found similar error messages to mine online, however, when the registry was searched for the CLSID in the error message, the user seemed to be able to find a fault in their registry with a double entry of versions. In my case, when I search my registry for "000208DB-0000-0000-C000-000000000046", I get no results.
When I installed VS 2017, I installed the following packages with it: Universal Windows Platform development, .NET desktop development and Desktop development with C++. Am I missing an important one?
Any help would be greatly appreciated, I have spent hours trawling through forums trying to see if the solution that worked for somebody with a similar problem to me would apply to my case, but so far I've had no luck.
Change Dim excelWB As Excel.Workbooks
to Dim excelWB As Excel.Workbook
and try again.
User contributions licensed under CC BY-SA 3.0