Sub ExportExcel()
Dim rst As DAO.Recordset
Dim objXL As Object 'Excel.Application
Dim xlWB As Object 'Workbook
Dim xlWS As Object 'Worksheet
Dim strSQL As String
Dim TblName As String, refRC As String
Dim x As Long
'TableName
TblName = "TableA"
'ID num
x = 1
'The row/col reference
refRC = Nz(DLookup("ReferenceRC", TblName, "ID =" & x), 0)
'SQL String creation
strSQL = "SELECT * FROM " & TblName
'create excel object and make it visible
Set objXL = CreateObject("Excel.Application")
objXL.Visible = True
Set xlWB = objXL.workbooks.Open("filepath") 'filepath here
Set xlWS = xlWB.worksheets("sheet1") 'sheet name here
Set rst = CurrentDb.OpenRecordset(strSQL)
'Go through all recordset
With rst
Do Until .EOF
xlWS.range(refRC).Value = rst!fname 'field name
'increment variables
x = x + 1
'The row/col reference
refRC = Nz(DLookup("ReferenceRC", TblName, "ID =" & x), 0)
.MoveNext 'go to next record in query
Loop
End With
'close recordset
rst.Close
Set rst = Nothing
End Sub