Dim con As Object
Set con = Application.CurrentProject.Connection
Dim rstExcel As Object
Dim strSQLExcel As String
Dim xlObj As Object
Dim Sheet As Object
strSQLExcel = "SELECT * From Customers"
Set rstExcel = CreateObject("ADODB.Recordset")
rstExcel.Open strSQLExcel, con, 1 ' 1 = adOpenKeyset
Set xlObj = CreateObject("Excel.Application")
xlObj.Workbooks.Add
Set Sheet = xlObj.ActiveWorkbook.Sheets(1)
Sheet.Range("A1").CopyFromRecordset rstExcel
Dim strCSVFile As String
strCSVFile = "C:\Test.txt"
Sheet.SaveAs strCSVFile, xlCSV
rstExcel.Close
Set rstExcel = Nothing
xlObj.Quit '**********
Set xlObj = Nothing
Set con = Nothing
|