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