Sunday, November 17, 2013

VB6 DATAGRID EXPORT TO EXCEL

//First ... ADD Reference Microsoft Excel Library

Dim xl As Excel.Application
Dim fldCount As Integer
Dim recCount As Long
Dim iCol As Integer
Dim iRow As Integer

   Set xl = New Excel.Application
   With xl
       .Workbooks.Add
       .Worksheets(1).Name = "Export Daily"
                     ' Copy field names to the first row of the worksheet
               fldCount = Adodc1.Recordset.Fields.Count
                For iCol = 1 To fldCount
                   xl.Cells(1, iCol).Value = Adodc1.Recordset.Fields(iCol - 1).Name
               Next
    
      
       Call .ActiveSheet.Range("A2").CopyFromRecordset(Adodc1.Recordset)
       .Visible = True
   End With