Sub exp2XL()
Dim xlObj As Object, rs As DAO.recordset
Dim j As Integer, rowCnt As Integer, curRow As Integer
Dim filePathName As String
filePathName = "c:\myFolder\myExcel.xls"
Set xlObj = CreateObject("excel.application")
xlObj.workbooks.Open filePathName
With xlObj
.worksheets(1).Select
Set rs = CurrentDb.OpenRecordset("qry_RN")
For j = 0 To rs.Fields.Count - 1
.cells(1, j + 1).Value = rs(j).Name
Next
.Range("A2").copyfromrecordset rs
rowCnt = .worksheets(1).usedrange.rows.Count
Set rs = CurrentDb.OpenRecordset("qry_RN_Casual")
For j = 0 To rs.Fields.Count - 1
.cells(rowCnt + 3, j + 1).Value = rs(j).Name
Next
.Range("A" & rowCnt + 4).copyfromrecordset rs
rowCnt = .worksheets(1).usedrange.rows.Count
Set rs = CurrentDb.OpenRecordset("qry_PT")
For j = 0 To rs.Fields.Count - 1
.cells(rowCnt + 3, j + 1).Value = rs(j).Name
Next
.Range("A" & rowCnt + 4).copyfromrecordset rs
rowCnt = .worksheets(1).usedrange.rows.Count
Set rs = CurrentDb.OpenRecordset("qry_PT_Casual")
For j = 0 To rs.Fields.Count - 1
.cells(rowCnt + 3, j + 1).Value = rs(j).Name
Next
.Range("A" & rowCnt + 4).copyfromrecordset rs
rowCnt = .worksheets(1).usedrange.rows.Count
.activeworkbook.Save
End With
xlObj.Quit
rs.Close
End Sub
|