System.Runtime.InteropServices.COMException (0x80010108) when creating an instance of Excel in vb.net 3.5

0

So, I have a program that launches an instance of Excel. It works on my machine as well as the machines of 2 others, but when my project leader tries it, he gets the following error:

    System.Runtime.InteropServices.COMException (0x80010108): Creating an instance of the COM component with CLSID {00024500-0000-0000-C000-000000000046} from the IClassFactory failed due to the following error: 80010108.

The code below is where I'm creating the excel instance and launching it.

    Dim xlsApp As New Excel.Application
    Dim xlsWB As Excel.Workbook
    Dim xlsWS As Excel.Worksheet

    Try
        If ugLoadDeviationsDetails.DataSource IsNot Nothing Then

            'Creates a temporary excel file with data located in the grid
            UltraGridExcelExporter1.Export(ugLoadDeviationsDetails, "C:\ProgramData\Data-Tronics\ShellFiles\LoadDeviations\tempExcel")

            xlsWB = xlsApp.Workbooks.Open("C:\ProgramData\Data-Tronics\ShellFiles\LoadDeviations\tempExcel")

            xlsWS = DirectCast(xlsWB.Sheets("Sheet1"), Excel.Worksheet)
            DirectCast(xlsWS.Cells.EntireRow, Excel.Range).ClearFormats()
            DirectCast(DirectCast(xlsWS.Cells("1", "A"), Excel.Range).EntireRow().Cells, Excel.Range).Interior.Color = Color.LightGray.ToArgb

            DirectCast(xlsWS, Excel.Worksheet).Copy()

            xlsWB.Close(False)

            xlsApp.Visible = True
            xlsApp.UserControl = True

        Else
            RaiseEvent ShowError("Cannot write file when grid is empty.")
        End If 
    Catch ex As Exception

        For Each wb As Excel.Workbook In xlsApp.Workbooks
            wb.Close(False)
        Next
        xlsApp.Quit()
    Finally
        xlsApp = Nothing
        xlsWB = Nothing
        xlsWS = Nothing
    End Try

According to the stacktrace it breaks on the following line:

    Dim xlsApp As New Excel.Application

The project lead uses the exact same version of Excel as I do (2010), can anyone think of any reason as to why this may occur, and how I may fix it?

.net
vb.net
office-interop
excel-interop
asked on Stack Overflow Oct 22, 2012 by Sai

1 Answer

0

Try this

xlsApp = CreateObject("Excel.Application")
xlsBook = xlsApp.Workbooks.Add
xlsSheet = xlsBook.Worksheets.Add
answered on Stack Overflow Nov 5, 2012 by Quannt

User contributions licensed under CC BY-SA 3.0