Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I am retriving the values to dataset and trying to upload those values to excel .
But i am getting this error Cannot create ActiveX component.The code is pasted below.
VB
Public Function CreateXLObjects(ByVal XLName As String) As Object
        Try
            XL = CreateObject("Excel.Application")
            Dim TemplateXL As String = XLName
            If TemplateXL.Substring(TemplateXL.Length - 1) <> "\" Then TemplateXL = TemplateXL & "\"
            TemplateXL = TemplateXL & "SS 2 1-ClosureReport.xls"
            WB = XL.Workbooks.Add(TemplateXL)
            Return WB
        Catch ex As Exception
        End Try
        Return WS
    End Function

when trying to createobject i.e XL = CreateObject("Excel.Application").
Please help me its very urgent
Posted
Updated 8-Oct-12 20:55pm
v2
Comments
chandanadhikari 10-Oct-12 10:46am    
hi,
i would first check if the reference for MS Excel is added correctly .

Havent used CreateObject before but why dont you use the code here as a template instead:
http://support.microsoft.com/kb/302084[^]
 
Share this answer
 
Here is my code
VB
'excel
Dim oexcel As Object
oexcel = CreateObject("Excel.Application")
Dim obook As Excel.Workbook
Dim osheet As Excel.Worksheet
Dim fnExc As String
Dim curLine As Integer = 0

' this should be used only once
obook = oexcel.Workbooks.Add

'first
If oexcel.Application.Sheets.Count() < 1 Then
    osheet = CType(obook.Worksheets.Add(), Excel.Worksheet)
Else
    osheet = oexcel.Worksheets(1)
End If
osheet.Name = "Payroll Detail Report"

'second
If oexcel.Application.Sheets.Count() < 2 Then
    osheet = CType(obook.Worksheets.Add(), Excel.Worksheet)
Else
    osheet = oexcel.Worksheets(2)
End If
osheet.Name = "Payroll Detail Report (real)"

'third
If oexcel.Application.Sheets.Count() < 3 Then
    osheet = CType(obook.Worksheets.Add(), Excel.Worksheet)
Else
    osheet = oexcel.Worksheets(3)
End If
osheet.Name = "Payroll Summary Report"

'next
If oexcel.Application.Sheets.Count() < 4 Then
    osheet = CType(obook.Worksheets.Add(), Excel.Worksheet)
Else
    osheet = oexcel.Worksheets(4)
End If
osheet.Move(After:=obook.Worksheets(obook.Worksheets.Count))
osheet.Name = "Weekly Payroll Report - Week 1"


obook.SaveAs(fnExc)
obook.Close()
obook = Nothing



Same video example http://www.youtube.com/watch?v=BaYxwKUnw0U[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900