0
A
回答
1
您可以使用VBA吗?
智能感知会帮助你,但上手:
DoCmd.TransferSpreadsheet acExport,acSpreadsheetTypeExcel9, “my_query_name”, “C:\ myfilename.xls”
注意:您可以有不同的Excel版本 “my_query_name”是你的查询或表 你需要设置文件位置的适当位置\名称的名称。扩展名
+0
我试过了,但我一直收到一个文件不存在在该位置错误。 – zSynopsis 2009-09-18 20:43:38
4
您可能需要考虑使用自动化来创建Excel电子表格并自行填充它,而不是使用宏。
这是我以前用过的功能。
Public Function ExportToExcel(FileToCreate As String, ByRef rst As ADODB.Recordset)
'Parms: FileToCreate - Full path and file name to Excel spreadsheet to create
' rst - Populated ADO recordset to export
On Error GoTo Err_Handler
Dim objExcel As Object
Dim objBook As Object
Dim objSheet As Object
'Create a new excel workbook; use late binding to prevent issues with different versions of Excel being
'installed on dev machine vs user machine
Set objExcel = CreateObject("Excel.Application")
Set objBook = objExcel.Workbooks.Add
'Hide the workbook temporarily from the user
objExcel.Visible = False
objBook.SaveAs (FileToCreate)
'Remove Worksheets so we're left with just one in the Workbook for starters
Do Until objBook.Worksheets.Count = 1
Set objSheet = objBook.Worksheets(objBook.Worksheets.Count - 1)
objSheet.Delete
Loop
Set objSheet = objBook.Worksheets(1)
rst.MoveFirst
'Use CopyFromRecordset method as this is faster than writing data one row at a time
objSheet.Range("A1").CopyFromRecordset rst
'The UsedRange.Rows.Count property can be used to identify the last row of actual data in the spreadsheet
'This is sometimes useful if you need to add a summary row or otherwise manipulate the data
'Dim lngUsedRange As Long
'lngUsedRange = objSheet.UsedRange.Rows.Count
'Save the spreadsheet
objBook.Save
objExcel.Visible = True
ExportToExcel = True
Err_Handler:
Set objSheet = Nothing
Set objBook = Nothing
Set objExcel = Nothing
DoCmd.Hourglass False
If Err.Number <> 0 Then
Err.Raise Err.Number, Err.Source, Err.Description
End If
End Function
+0
这段代码适合我,但唯一的问题是,Excel数据没有标题..我怎么能添加它? – 2016-04-12 07:18:12
相关问题
- 1. 将MS SQL Server查询结果导出到MS Access
- 2. MS Access窗体(VBA)查询和定期查询给出不同的结果
- 3. 以编程方式将MS Access查询结果导出到CSV
- 4. SQL查询在MS Access VBA
- 5. MS Access 2010 vba查询
- 6. MS Access VBA选择查询
- 7. MS Access VBA查询。选择其次,然后计算结果
- 8. 如何将MS Access查询的结果导出到Excel的特定工作表
- 9. 刷新MS Access查询(VBA代码)
- 10. 的MS Access VBA查询多个表
- 11. MS Access查询
- 12. MS ACCESS查询
- 13. 导入附加vba MS-Access
- 14. 如何在VBA/Access中查询设计的查询结果debug.print
- 15. 导出查询结果
- 16. 将查询导出到Excel并将数据放入表MS Access 2013 VBA
- 17. 查询的MS Access
- 18. MS Access子查询
- 19. MS Access PYODBC查询
- 20. 在MS Access VBA中使用选择查询更新查询
- 21. MS ACCESS vba - error
- 22. 的MS Access VBA
- 23. 从查询导出的数据结果
- 24. 将MS-Access表单结果导出到Excel?
- 25. MS Access在表格上显示查询结果
- 26. MS Access 2007中查询到任何结果
- 27. MS Access 2010:如何避免不可编辑的查询结果?
- 28. 在MS Access中获取SQL查询结果但不在VBScript中
- 29. Access表,无法导出隐藏查询
- 30. 的MS Access导出查询到Excel文件模板
你可以发布你的代码吗? (在我的回答中,你表示你试过docmd。) – JeffO 2009-09-18 21:03:39
什么是Excel的目标版本?行数的限制毫无疑问是Excel的限制,而不是Access的限制。 Excel 2007增加了行数,顺便说一句。 – 2009-09-20 02:52:28
事实上,托尼,我认为Access 2002标签在这里是有用的信息,因为它限制了导出格式。当然,我认为应该使用标签的方式是只应使用MS-ACCESS,并在问题中指出特定版本,但是您删除了标签但未将版本添加到问题文本中。在我看来,这会丢失有用的信息。 – 2010-09-11 19:41:16