I would like to export my data in DataGrid to excel. It could be sent to excel but there are errors on rows.
I would also like to know how to export the column headers to excel along.
VB Code:
Private Sub cmdExport_Click() Dim objExcel As Excel.Application Dim objWorkbook As Excel.Workbook Dim i As Long Dim n As Long On Error Resume Next Set objExcel = GetObject(, "Excel.Application") If Err.Number Then Err.Clear Set objExcel = CreateObject("Excel.Application") If Err.Number Then MsgBox "Can't open Excel." End If End If objExcel.Visible = True Set objWorkbook = objExcel.Workbooks.Add AppActivate "DataGrid To Excel Demo" For i = 0 To DataGrid1.Row.Count -1 <======= Error here DataGrid1.Row = i For n = 0 To DataGrid1.Columns.Count - 1 DataGrid1.Col = n objWorkbook.ActiveSheet.Cells(i + 1, n + 1).Value = DataGrid1.Text Next Next End Sub


Reply With Quote