10 Replies - 467 Views - Last Post: 01 August 2019 - 05:16 AM Rate Topic: -----

#1 DarenR   User is offline

  • D.I.C Lover

Reputation: 624
  • View blog
  • Posts: 4,165
  • Joined: 12-January 10

Cannot create ActiveX component.

Posted 31 July 2019 - 11:20 AM

i am trying to make an excel file .

this works when i run it right from my tfs
when i run it from my iis it breaks and Cannot create ActiveX component.

i have microsoft.interlop and excel referenced in my application

i create my excel sheet as follows

  _excelDataset = _exceldataGrab.SQLDataGrab(_userID, _CreatedDate)

        _excel = CreateObject("Excel.Application.14")
        _excelBook = _excel.WorkBooks.add

        for Each _dc in _excelDataset.Tables(0).Columns
            _colIndex = _colIndex + 1
            _excel.Cells(1,_colIndex) = _dc.ColumnName
        Next

        For each _dr in _excelDataset.tables(0).rows
            _RowIndex = _RowIndex + 1
            _colIndex = 0
            For each _dc in _excelDataset.Tables(0).Columns
                _colIndex = _colIndex + 1
                _excel.Cells(_RowIndex + 1, _colIndex) = _dr(_dc.ColumnName)
                
            Next

        Next
        
        _excelSheet = _excel.Worksheets(1)
        _excelSheet.Name = "Route Frequency"
        _excelSheet.Cells.Select()
        _excelSheet.Columns.AutoFit()
        _excelSheet.Rows.AutoFit()
        
      ' _excelSheet.Range("A1").Value = "Yippy" '' this adds to the cell

        _excelBook.SaveAs(_fullPath)

        _excelBook.Close()
        _excelBook = nothing
       ' 
        _excel = nothing
       
        return _excelBook
         _excel.quit()
    End Function



        
        _ExcelBook = _ExcelBookExport.createExcelExport(_path, Session("userID"),DateTime.Now.Date, _divisionID)
      TRY
        Response.ContentType = "application/pdf"  
        Response.AppendHeader("Content-Disposition", "attachment; filename= RouteFrequency" & Session("userID") & _divisionID & _formattedDate & ".xlsx")  
        Response.TransmitFile(Server.MapPath("~/ExcelDownloads/RouteFrequency" & Session("userID") & _divisionID & _formattedDate & ".xlsx"))  
        Response.End() 
      CATCH Ex As Exception
          msgLbl.Text = Ex.ToString()
      FINALLY 

            HttpContext.Current.ApplicationInstance.CompleteRequest()
        
          deleteExistingExcelExport()
      END TRY



we have 0ffice 365

This post has been edited by DarenR: 31 July 2019 - 11:21 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Cannot create ActiveX component.

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15160
  • View blog
  • Posts: 60,694
  • Joined: 12-June 08

Re: Cannot create ActiveX component.

Posted 31 July 2019 - 11:45 AM

Is it crapping an error on you?

I used this in another post semi recently and it worked fine. You maybe trying to over specify.

  Dim objApp As Excel.Application
        Dim objBook As Excel._Workbook
        Dim objBooks As Excel.Workbooks
        Dim objSheets As Excel.Sheets
        Dim objSheet As Excel._Worksheet

        Try
            objApp = New Excel.Application() '-- new app
            objBooks = objApp.Workbooks '-- add collection of workbooks to it.
            objBook = objBooks.Add '-- get a handle to a new book in the collection of books
            objSheets = objBook.Worksheets '-- get a handle to the array of work sheets in the book.
            objSheet = objSheets(1) '-- specific sheet.
            objSheet.Name = "foo" '-- give it a name.

            Dim objRange As Excel.Range = objSheet.Range("A1", "A1") '-- from teh sheet get a range
            objRange.Value = "bar" '-- give the range a value.

            objApp.DisplayAlerts = False

            objBook.SaveAs("C:\test\test3.xlsx") '-- save the book.

            objApp.Quit() '-- release stuff

            objRange = Nothing '-- cleanup
            objSheet = Nothing
            objSheets = Nothing
            objBooks = Nothing
        Catch ex As Exception
            Debug.WriteLine(ex.Message)
            Stop
        End Try

Was This Post Helpful? 0
  • +
  • -

#3 DarenR   User is offline

  • D.I.C Lover

Reputation: 624
  • View blog
  • Posts: 4,165
  • Joined: 12-January 10

Re: Cannot create ActiveX component.

Posted 31 July 2019 - 11:57 AM

i capture the exception in a log

RouteFreq_7/31/2019_System.Exception: Cannot create ActiveX component.
   at Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName)
   at RouteFequency.ExcelCreate.createExcelExport(String _path, String _userID, DateTime _CreatedDate, String _divisionId) in O:\code\Web Portals\RouteFrequency\RouteFequency\RouteFequency\Classes\ExcelCreate.vb:line 35



this is my line 35
 _excel = CreateObject("Excel.Application")

This post has been edited by DarenR: 31 July 2019 - 12:03 PM

Was This Post Helpful? 0
  • +
  • -

#4 DarenR   User is offline

  • D.I.C Lover

Reputation: 624
  • View blog
  • Posts: 4,165
  • Joined: 12-January 10

Re: Cannot create ActiveX component.

Posted 31 July 2019 - 12:02 PM

your line
 Dim objApp As Excel.Application



it is not recognized when i try it as a test... gets all red underlined and stuff
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15160
  • View blog
  • Posts: 60,694
  • Joined: 12-June 08

Re: Cannot create ActiveX component.

Posted 31 July 2019 - 12:05 PM

Imports is: Imports Excel = Microsoft.Office.Interop.Excel

.net 4.5
Was This Post Helpful? 0
  • +
  • -

#6 DarenR   User is offline

  • D.I.C Lover

Reputation: 624
  • View blog
  • Posts: 4,165
  • Joined: 12-January 10

Re: Cannot create ActiveX component.

Posted 31 July 2019 - 12:10 PM

i already have that import .

says excel.application is not defined ... is that your class name maybe?
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15160
  • View blog
  • Posts: 60,694
  • Joined: 12-June 08

Re: Cannot create ActiveX component.

Posted 31 July 2019 - 12:14 PM

Did you add it to the project's references?

No class name. Just pulled from my sandbox project sitting in main.
Was This Post Helpful? 0
  • +
  • -

#8 DarenR   User is offline

  • D.I.C Lover

Reputation: 624
  • View blog
  • Posts: 4,165
  • Joined: 12-January 10

Re: Cannot create ActiveX component.

Posted 31 July 2019 - 12:26 PM

do you think it maybe a permissions issue on the actual excel?

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#9 DarenR   User is offline

  • D.I.C Lover

Reputation: 624
  • View blog
  • Posts: 4,165
  • Joined: 12-January 10

Re: Cannot create ActiveX component.

Posted 31 July 2019 - 12:37 PM

so i changed the create object to New Excel.Application and this is the error it now returns:

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)). 



so it looks like it is a permissions issue?
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15160
  • View blog
  • Posts: 60,694
  • Joined: 12-June 08

Re: Cannot create ActiveX component.

Posted 31 July 2019 - 01:24 PM

It maybe. Are these complex excel spreadsheets? Again - you could make a CSV, label it .XLS, and go about your way. Excel will open it.
Was This Post Helpful? 0
  • +
  • -

#11 DarenR   User is offline

  • D.I.C Lover

Reputation: 624
  • View blog
  • Posts: 4,165
  • Joined: 12-January 10

Re: Cannot create ActiveX component.

Posted 01 August 2019 - 05:16 AM

so after a shit ton of research -- i found a solution-- not the best but a work around for now -- you have to set the app pool to localsystem
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1