How to export datagrid data on vb6 to excel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vbdude
    New Member
    • Mar 2008
    • 5

    #1

    How to export datagrid data on vb6 to excel

    Hi,

    I want help with my problem.

    How can i export datagrid data that comes from a ms sql server 2005 and will be going to ms excel..

    Vbdude...

    P.S. Please Help me!!!
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    what have you tried ?

    are you struck some where in the code ?

    Comment

    • vbdude
      New Member
      • Mar 2008
      • 5

      #3
      i try this one but I dont have any adodc
      -----------------------------------------------------------------------
      Private Sub btn_export_Clic k(Index As Integer)
      Dim oExcel As Object
      Dim oBook As Object
      Dim oSheet As Object
      Dim j As Integer
      Set oExcel = CreateObject("E xcel.Applicatio n")
      Set oBook = oExcel.Workbook s.Add
      Set oSheet = oBook.Worksheet s(1)
      On Error GoTo errcode
      With oBook.Worksheet s("sheet1").Row s(1)
      .Font.Bold = True
      For j = 0 To DataGrid1.Colum ns.count - 1
      Worksheets("she et1").Cells(1, j + 1).Value = DataGrid1.Colum ns(j).Caption
      Next j
      End With
      oSheet.Range("A 2").CopyFromRec ords Adodc1.Recordse t
      oBook.Open
      oBook.SaveAs
      oExcel.Quit
      Exit Sub
      errcode:
      MsgBox Err.Description , , Err.Source

      End Sub


      the error is "Object doesn't support this property or method"

      Comment

      • vbdude
        New Member
        • Mar 2008
        • 5

        #4
        i have declared rsEmployee as ADODB.Recordset

        what should be the alternative to the adodc1.recordse t?

        ow.. they dont have any data to excel...

        thank you for the reply and advance

        Comment

        Working...