Exporting from queries in vb into excel with Header

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • monadel
    New Member
    • Sep 2007
    • 17

    #1

    Exporting from queries in vb into excel with Header

    Hi Guys,

    Can anyone help me with this problem please. I cant export a queries that I wrote in vb script into excel with Header according into the queries that I wrote.
    I can export the data but without the header. I want additional header from the queries.

    Thanks guys.
  • monadel
    New Member
    • Sep 2007
    • 17

    #2
    This is my code to export into excel. So where should I add the Header??

    Public Function ExportToFile(By Val filepath As String, ByVal rs As DAO.Recordset, ByRef columnStart As Integer) As Boolean

    Dim xl As Excel.Applicati on
    Dim wb As Excel.Workbook
    Dim ws As Excel.Worksheet
    Dim fld As DAO.Field
    Dim x As Integer
    Dim i As Integer

    Set xl = New Excel.Applicati on

    If FileExists(file path) And Not filepath = "" Then
    Set wb = xl.Workbooks.Op en(filepath, False, False)
    Set ws = wb.Worksheets.A dd
    Else
    Set wb = xl.Workbooks.Ad d
    Set ws = wb.Worksheets(1 )
    End If

    i = 1
    Do While Not rs.EOF()
    x = columnStart
    For Each fld In rs.fields
    Select Case fld.Type
    Case dbBinary, dbGUID, dbLongBinary, dbVarBinary
    ' This type of data can't export to excel
    Case Else
    ws.Cells(i, x).Value = rs.fields(fld.N ame).Value
    x = x + 1
    End Select
    Next
    rs.MoveNext
    i = i + 1
    Loop


    xl.Visible = True
    ExportToFile = True

    exit_errorhandl er:
    ' Release the objects.
    Set ws = Nothing
    Set wb = Nothing
    Set xl = Nothing
    Exit Function

    errorhandler:
    ExportToFile = False
    MsgBox "Problem with the reading of the date into the file." & vbCr & Err.Description , vbCritical, csAppName
    Resume exit_errorhandl er:

    End Function

    Comment

    • monadel
      New Member
      • Sep 2007
      • 17

      #3
      anyone? please help me.

      Comment

      • monadel
        New Member
        • Sep 2007
        • 17

        #4
        please. how do you do to export data into excel with header?

        Comment

        Working...