Results 1 to 2 of 2

Thread: DataGrid problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    13

    DataGrid problem

    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:
    1. Private Sub cmdExport_Click()
    2.     Dim objExcel As Excel.Application
    3.     Dim objWorkbook As Excel.Workbook
    4.     Dim i As Long
    5.     Dim n As Long
    6. On Error Resume Next
    7.     Set objExcel = GetObject(, "Excel.Application")
    8. If Err.Number Then
    9.    Err.Clear
    10.    Set objExcel = CreateObject("Excel.Application")
    11.    If Err.Number Then
    12.       MsgBox "Can't open Excel."
    13.    End If
    14. End If
    15. objExcel.Visible = True
    16. Set objWorkbook = objExcel.Workbooks.Add
    17. AppActivate "DataGrid To Excel Demo"
    18.  
    19.     For i = 0 To DataGrid1.Row.Count -1 <======= Error here
    20.         DataGrid1.Row = i
    21.     For n = 0 To DataGrid1.Columns.Count - 1
    22.         DataGrid1.Col = n
    23.         objWorkbook.ActiveSheet.Cells(i + 1, n + 1).Value = DataGrid1.Text
    24.     Next
    25.     Next
    26. End Sub

  2. #2

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    13
    Can anyone teach me how to export the 'columnheader' in DataGrid to Excel?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width