I looked at some on here and found this:
Im having a problem with - xlWorkSheet.Cells(i + 1, j + 1)Code:Public Sub Test() Dim xlApp As Global.Excel.Application Dim xlWorkBook As Global.Excel.Workbook Dim xlWorkSheet As Global.Excel.Worksheet Dim misValue As Object = System.Reflection.Missing.Value Dim i As Integer Dim j As Integer 'xlApp = Excel.Application xlWorkBook = xlApp.Workbooks.Add(misValue) xlWorkSheet = xlWorkBook.Sheets("sheet1") For i = 0 To DataGridView1.RowCount - 2 For j = 0 To DataGridView1.ColumnCount - 1 xlWorkSheet.Cells(i + 1, j + 1) = _ DataGridView1(j, i).Value.ToString() Next Next xlWorkSheet.SaveAs("C:\vbexcel.xlsx") xlWorkBook.Close() xlApp.Quit() releaseObject(xlApp) releaseObject(xlWorkBook) releaseObject(xlWorkSheet) MsgBox("You can find the file C:\vbexcel.xlsx") End Sub
Any ideas to fix this or another way to export to excel?




Reply With Quote