Copy the Data from Access to Excel - in new Workbook

     

    Sub Create_RecordSet()
    Dim cn As ADODB.Connection
    Set cn = CurrentProject.Connection
    Dim rs As New ADODB.RecordSet
    rs.ActiveConnection = cn
    'Retrive records through SQL Query
    Dim SQL As String
    SQL = "Select * from Employees"
    rs.Open SQL
    'To open Employees Table
    'rs.Open "[Employees]"
    'Retrive records through SQL Query
    'rs.Open "Select Department,Gender from Employees"
    'Define Excel application object
    Dim XL As Excel.Application
    Set XL = CreateObject("Excel.Application")
    XL.Visible = True
    'Define Excel Workbook object
    Dim wkb As Excel.Workbook
    Set wkb = Workbooks.Add
    wkb.Windows(1).Visible = True
    'Define Excel sheet object
    Dim sh As Worksheet
    Set sh = wkb.Sheets("Sheet1")
    sh.Range("A5").CopyFromRecordset rs
    rs.Close
    MsgBox "Recordset Copied by Creating new Workbook"
    End Sub

    Download the Workbook