I have asked this question in VB.NET and I am asking of more help here.

I have tried to create an Excel report from VB.net in different ways and each one has a problem of its own. The most recent way I tried was to use ActiveX com. I tried different codes online and they all ended up with the following error:

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

Idown vote favorite I have tried to create an Excel report from VB.net in different ways and each one has a problem of its own. The most recent way I tried was to use ActiveX com. I tried different codes online and they all ended up with the following error:

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

I checked the error online and tried all solutions but I still get the same error on the following line:

Dim xlObject As New Excel.Application() or similar line in different page:

Dim oXL As Excel.Application = New Microsoft.Office.Interop.Excel.Application() The program does not move to the next line and it means there is something wrong there.

Things I have done so far are:

1- I added references for Microsoft.Office.Interop.Excel and Microsoft Office 14.0 Object Library

2- I added Imports Excel = Microsoft.Office.Interop.Excel Imports Microsoft.Office.Interop at the top of my code

3- I took care of objects created after the program finished working with them either using Try...Catch...Finally or without it. I used xlObject.Workbooks.Close() and xlObject.Quit() and Marshal.FinalReleaseComObject for workbook, worksheet and range objects.

4- I tried assigning a workbook name (C:\Contracts\Filename.xls or C:\Contracts\Filename.xlsx) or let the program to create one. I gave all permissions to NetWork Service, myself as the user, IIs_IUSRS to the folder containing the filename.xls.

5- I changed dcomcnfg/component Services/Computers/My Computer/DCOM Config/Microsoft Excel Application Properties/Security tab and added Network Service account with Local Launch and Local Activation Permissions and Local Access Permission. After a lot of trial and error ways, I also added the same permissions to the dcomcnfg/component Services/Computers/My Computer properties.

I even copied some of online codes to my page and tried them. I am working on Windows Server 2008 SP 1, 64-bit OS and MS Office Professional 2010 version 14.0 (64-bit) and view the page from localhost.

Here is the latest code I tried:

Imports Excel = Microsoft.Office.Interop.Excel 'Imports Microsoft.Office.Interop

Public Class TestExcel5 Inherits System.Web.UI.Page

Private Sub btnWrite_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles btnWrite.Click

    Dim Testmsg As String = ""
    Try
        Dim xlApp As Excel.Application = New Microsoft.Office.Interop.Excel.Application()


        If xlApp Is Nothing Then
            AlertUserMsgBox("Excel is not properly installed!!")
            Testmsg = "Excel is not properly installed!!"
            Return
        End If

        Testmsg = "Passed creating the Excel object......"

        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet
        Dim misValue As Object = System.Reflection.Missing.Value

        xlWorkBook = xlApp.Workbooks.Add(misValue)
        xlWorkSheet = xlWorkBook.Sheets("sheet1")
        xlWorkSheet.Cells(1, 1) = "Sheet 1 content"

        xlWorkBook.SaveAs("C:\Contracts\Excel5.xlsx", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, _
         Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue)
        xlWorkBook.Close(True, misValue, misValue)
        xlApp.Quit()

Related posts

Recent Viewed