Hi everyone!!

I am using this code to write a new excel spreadsheet from VB.NET and populate it with values.However I keep getting the error "cannot create active x component."I am thinking it has something to do with security features but Im just wondering if anyone has any ideas!!



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

MakeNewFile()

Dim sConn As String

sConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\temp\NewExcel.xls; Extended Properties=Excel 8.0;"

Dim objConn As New System.Data.OleDb.OleDbConnection(sConn)

objConn.Open()

Dim objCmd As New System.Data.OleDb.OleDbCommand

objCmd.Connection = objConn

objCmd.CommandText = "Insert into [Sheet1$] (TitleOne, TitleTwo, TitleThree, TitleFour, TitleFive) values ('This', 'is', 'just', 'some', 'text')"

objCmd.ExecuteNonQuery()

objCmd.Dispose()

objConn.Close()

End Sub



Sub MakeNewFile()

Dim oExcel As Object

Dim oBook As Object

Dim oSheet As Object

oExcel = CreateObject("Excel.Application")

oBook = oExcel.Workbooks.Add

oSheet = oBook.Worksheets(1)

oSheet.Range("A1").value = "TitleOne"

oSheet.Range("B1").value = "TitleTwo"

oSheet.Range("C1").value = "TitleThree"

oSheet.Range("D1").value = "TitleFour"

oSheet.Range("E1").value = "TitleFive"

oBook.SaveAs("c:\temp\NewExcel.xls")

oBook.Close()

System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)

oSheet = Nothing

oBook = Nothing

oExcel = Nothing

GC.Collect()

End Sub

Thank you!

Julie