1

Created several Vb.net(studio 2015) front end with MSSQL back end for data management. They all use office to export reports. We currently use Office 2010 and have no problems (Windows 7).

Some of the PCs have started to get Office 2016, and this is where suddenly I have ran into issues.

A Snippet a code here just to show.

Imports Excel = Microsoft.Office.Interop.Excel
Dim oExcel As Microsoft.Office.Interop.Excel.Application
oExcel = CreateObject("Excel.Application")
Dim wBook As Microsoft.Office.Interop.Excel.Workbook
Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet
wBook = oExcel.Workbooks.Add()
wSheet = wBook.ActiveSheet()
With oExcel
  .SheetsInNewWorkbook = 1
  .Worksheets(1).Select()
  Dim i As Integer = 2
  .Cells(i, 1).value = "SUPERVISOR NAME"
  .Cells(i, 2).value = "TOTAL"
   For Col = 0 To Workflow_Set.Tables("Workflow").Rows.Count - 1
       .Cells(i, Col + 3).value = RNF(Workflow_Set, "Workflow", Col, "Description")
       .Cells(i, Col + 3).EntireColumn.AutoFit()
   Next
 .Visible = True

So I tried to install Office 2016 on my machine. Based off that code I get the error. I completely uninstalled 2010. I swapped all the references in my project from Office 14.0 to 16.0. It compiles just fine. But when I go to actually run the calls I get hit with the same issues as before.

"An unhandled exception of type 'System.Exception' occurred in Microsoft.VisualBasic.dll Additional information: Cannot create ActiveX component." On the line " oExcel = CreateObject("Excel.Application")"

Ok, so I try to change that to simple "oExcel= New excel.Application" Now that Gives a COM error. An unhandled exception of type "'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll Additional information: Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."

I saw in another thread about using that to search for legacy outdated info, but that regkey ID doesn't SEEM to lead to anything. I have been trying isntalled different packages. Looking trhough Registry stuff for old office 2010 with no luck. I don't know what to do get this issues resolved at this point.

BC44
  • 11
  • 1
  • 2
  • Try `oExcel = new Microsoft.Office.Interop.Excel.Application()` to use the version referenced by your code. `CreateObject` may find the wrong version in the registry. See https://stackoverflow.com/questions/170070/what-are-the-differences-between-using-the-new-keyword-and-calling-createobject – djv Sep 13 '17 at 18:26
  • "oExcel = New Microsoft.Office.Interop.Excel.Application()" Give the same COM error – BC44 Sep 13 '17 at 18:48
  • Can you create a new project with Office 2016 references and see if it works? – djv Sep 13 '17 at 18:50
  • Tried that before I made this question. Same issue. Same with opening pre-built and released older projects that have the old Office 2010 references. – BC44 Sep 13 '17 at 19:58
  • Do you have `Embed Interop Types = True` on the reference properties? – djv Sep 13 '17 at 20:50

0 Answers0