Created
October 7, 2015 21:19
-
-
Save levonlee/60119d569690d688d1d4 to your computer and use it in GitHub Desktop.
Export queries to Excel in Access using VBA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Option Compare Database | |
| Option Explicit | |
| Sub ExportToXlsx() | |
| Dim cdb As DAO.Database, qdf As DAO.QueryDef | |
| Set cdb = CurrentDb | |
| Dim xlsxPath As String | |
| xlsxPath = "C:\GP_NBM_2012.xlsx" | |
| Set qdf = cdb.CreateQueryDef("01", _ | |
| "SELECT * FROM t1 WHERE b like '*-2012-01*'") | |
| Set qdf = Nothing | |
| DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "01", xlsxPath, True | |
| DoCmd.DeleteObject acQuery, "01" | |
| Set qdf = cdb.CreateQueryDef("02", _ | |
| "SELECT * FROM t1 WHERE b like '*-2012-02*'") | |
| Set qdf = Nothing | |
| DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "02", xlsxPath, True | |
| DoCmd.DeleteObject acQuery, "02" | |
| Set cdb = Nothing | |
| End Sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment