Neelsfer:
-
Option Compare Database
-
Sub zj_excel_query2sheet_1()
-
Dim fileName, qryout As String
-
fileName = "C:\Documents and Settings\All Users\Workbook1.xlsx"
-
qryout = "Query1"
-
DoCmd.TransferSpreadsheet acExport,acSpreadsheetTypeExcel12Xml, qryout, fileName, True
-
End Sub
A few things...
-- for the "filename" you might try leaving the ".xlsx" off so that, in this example, the name becomes just "Workbook1"
-- "qryout" this must be a "stored" query... that is it must be part of the querydefs collection. So you either need to have it defined by hand... or do as I do and create the querydef and add to the collection as needed for each query... not really all that hard.
-- the last entry "true" will place the field names to headers.
-- enter the code into a module and then [F1] for more information.