Hi, I'm trying to create an excel 2003 workbook from my vb.net project
I referenced the code from this website
http://www.dotnetspider.com/resources/20382-To-create-Excel-file-vb-net.aspx
However i'm getting error on this line "objSheets = objBook.Worksheets"
Can any please tell me what's wrong?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
''Create the Excel object declaration
Dim objExcel As Excel.Application = Nothing
' create a excel workbooks object
Dim objBooks As Excel.Workbooks = Nothing
' create a workbook object
Dim objBook As Excel.Workbook = Nothing
' create a excel sheets object
Dim objSheets As Excel.Worksheets = Nothing
' create a excel sheet object
Dim objSheet As Excel.Worksheet = Nothing
' create a excel range object
Dim objRange As Excel.Range = Nothing
' create a excel application object
objExcel = New Excel.Application
objExcel.Visible = True
objExcel.DisplayAlerts = False
objBook = CType(objExcel.Workbooks.Add(), Excel.Workbook)
objBooks = objExcel.Workbooks
objSheet = CType(objBooks(1).Worksheets.Item(1), Excel.Worksheet)
objSheets = objBook.Worksheets
' Adding multiple worksheets to workbook
objSheets.Add(Count:=2)
'Adding First Sheet
objBook = objBooks.Item(1)
objSheet = CType(objSheets.Item(1), Excel.Worksheet)
' Assigning the worksheet name and summary log file values
objSheet.Name = "Result Summary"
objRange = objSheet.CellsWriteDataToExcel(objRange)
objExcel.Cells(2, 1).Value = "Product Name"
objExcel.Cells(3, 1).Value = "Comments"
objExcel.Cells(4, 1).Value = "Date and Time"
End Sub
Thanks!