Copy the Data from Access to Excel - Existing workbook

     

  • Create a Workbook and save in "D" Folder
  •  

  • Name that workbook as "Copy_Data_From_AccessToExcel"
  •  

    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
    Dim Ex As Excel.Application
    Set Ex = CreateObject("Excel.Application")
    Ex.Visible = True
    Dim Source As String
    Source = "D:\Copy_Data_From_AccessToExcel.xlsx"
    Dim wkb As Excel.Workbook
    Set wkb = GetObject(Source)
    wkb.Windows(1).Visible = True
    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 File