Import and export with Excel
Colleagues send lists as Excel files, accounts want reports back as Excel. With External Data that works once; with TransferSpreadsheet in VBA it works the same way every month.
In short: DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "query", "C:\Data\File.xlsx", True writes a table or query to an Excel file. With acImport Access reads a file in: into a new table or appended to an existing one. True means the first row holds the field names.
Before you start: Recordset.
Try it now
Task Write the procedure ExportOpen: it exports the saved query qOpenOrders as an Excel workbook to C:\Data\Open orders.xlsx, with field names in the first row.
Orders 120 rows, 6 columns
| OrderID | CustomerID | OrderDate | ShippedDate | Freight | PaymentMethod |
|---|---|---|---|---|---|
| 1 | 16 | 30 Apr 2025 | 3 May 2025 | 4.90 | Invoice |
| 2 | 23 | 18 May 2025 | 26 May 2025 | 4.90 | PayPal |
| 3 | 19 | 16 Jul 2026 | 4.90 | Direct debit | |
| 4 | 11 | 31 Mar 2025 | 1 Apr 2025 | 0.00 | Invoice |
| 5 | 6 | 7 Dec 2025 | 9 Dec 2025 | 9.90 | PayPal |
| 6 | 18 | 19 May 2026 | 26 May 2026 | 6.90 | Direct debit |
| 7 | 7 | 15 Jun 2026 | 16 Jun 2026 | 4.90 | Credit card |
| 8 | 20 | 18 Mar 2025 | 19 Mar 2025 | 0.00 | PayPal |
| 9 | 10 | 29 Oct 2025 | 3 Nov 2025 | 0.00 | Direct debit |
| 10 | 7 | 21 Nov 2026 | 4.90 | Invoice | |
| 11 | 1 | 2 May 2025 | 10 May 2025 | 9.90 | Direct debit |
| 12 | 10 | 7 Aug 2025 | 9 Aug 2025 | 0.00 | Invoice |
| 13 | 3 | 17 Sep 2026 | 24 Sep 2026 | 9.90 | PayPal |
| 14 | 16 | 29 Jan 2026 | 1 Feb 2026 | 6.90 | Invoice |
| 15 | 4 | 13 Jun 2025 | 21 Jun 2025 | 4.90 | PayPal |
| 16 | 12 | 3 Nov 2025 | 12 Nov 2025 | 4.90 | Invoice |
| 17 | 9 | 5 May 2026 | 8 May 2026 | 9.90 | PayPal |
| 18 | 9 | 26 Sep 2025 | 2 Oct 2025 | 4.90 | PayPal |
| 19 | 14 | 8 Mar 2026 | 10 Mar 2026 | 0.00 | Credit card |
| 20 | 1 | 2 Apr 2026 | 6.90 | PayPal | |
| 21 | 18 | 17 Nov 2026 | 4.90 | PayPal | |
| 22 | 11 | 27 Jul 2026 | 4 Aug 2026 | 4.90 | PayPal |
| 23 | 12 | 23 Jun 2026 | 28 Jun 2026 | 4.90 | Credit card |
| 24 | 10 | 12 Jan 2026 | 16 Jan 2026 | 0.00 | Direct debit |
| 25 | 1 | 30 Mar 2026 | 31 Mar 2026 | 4.90 | Credit card |
| 26 | 3 | 3 Mar 2025 | 7 Mar 2025 | 4.90 | Invoice |
| 27 | 24 | 9 Mar 2025 | 11 Mar 2025 | 4.90 | PayPal |
| 28 | 1 | 22 Sep 2025 | 28 Sep 2025 | 4.90 | PayPal |
| 29 | 1 | 18 Feb 2025 | 22 Feb 2025 | 4.90 | Invoice |
| 30 | 19 | 13 Oct 2025 | 18 Oct 2025 | 4.90 | PayPal |
| 31 | 10 | 19 Sep 2025 | 25 Sep 2025 | 6.90 | PayPal |
| 32 | 6 | 19 Jun 2026 | 24 Jun 2026 | 4.90 | Credit card |
| 33 | 20 | 16 Jun 2026 | 22 Jun 2026 | 9.90 | Credit card |
| 34 | 13 | 23 May 2026 | 27 May 2026 | 9.90 | Direct debit |
| 35 | 16 | 24 May 2026 | 2 Jun 2026 | 4.90 | PayPal |
| 36 | 14 | 9 Nov 2026 | 14 Nov 2026 | 4.90 | PayPal |
| 37 | 3 | 11 Mar 2026 | 18 Mar 2026 | 9.90 | PayPal |
| 38 | 22 | 2 Jan 2025 | 10 Jan 2025 | 0.00 | Invoice |
| 39 | 12 | 21 Oct 2025 | 27 Oct 2025 | 0.00 | Invoice |
| 40 | 20 | 4 Nov 2026 | 5 Nov 2026 | 9.90 | PayPal |
| 41 | 17 | 29 Mar 2026 | 30 Mar 2026 | 4.90 | PayPal |
| 42 | 13 | 6 Jan 2026 | 8 Jan 2026 | 0.00 | Invoice |
| 43 | 3 | 24 Feb 2026 | 26 Feb 2026 | 4.90 | PayPal |
| 44 | 7 | 21 Sep 2026 | 28 Sep 2026 | 4.90 | Invoice |
| 45 | 2 | 17 Apr 2025 | 23 Apr 2025 | 0.00 | Direct debit |
| 46 | 7 | 27 Apr 2026 | 28 Apr 2026 | 4.90 | Invoice |
| 47 | 3 | 16 Nov 2026 | 6.90 | Direct debit | |
| 48 | 1 | 26 Jun 2026 | 27 Jun 2026 | 4.90 | Credit card |
| 49 | 24 | 29 Apr 2026 | 30 Apr 2026 | 4.90 | PayPal |
| 50 | 1 | 23 Mar 2025 | 28 Mar 2025 | 4.90 | Direct debit |
| 51 | 10 | 28 Jan 2026 | 31 Jan 2026 | 0.00 | PayPal |
| 52 | 22 | 9 May 2026 | 15 May 2026 | 4.90 | Direct debit |
| 53 | 10 | 29 Dec 2025 | 7 Jan 2026 | 0.00 | Credit card |
| 54 | 4 | 17 Oct 2026 | 18 Oct 2026 | 9.90 | Credit card |
| 55 | 24 | 30 Aug 2025 | 31 Aug 2025 | 6.90 | Credit card |
| 56 | 6 | 29 Jan 2026 | 2 Feb 2026 | 4.90 | PayPal |
| 57 | 18 | 10 Dec 2025 | 13 Dec 2025 | 6.90 | Direct debit |
| 58 | 13 | 4 Mar 2025 | 9 Mar 2025 | 9.90 | Invoice |
| 59 | 11 | 29 Nov 2025 | 7 Dec 2025 | 6.90 | Invoice |
| 60 | 9 | 30 Oct 2025 | 4 Nov 2025 | 4.90 | Invoice |
| 61 | 10 | 17 Mar 2026 | 19 Mar 2026 | 4.90 | PayPal |
| 62 | 9 | 14 Jul 2025 | 21 Jul 2025 | 4.90 | PayPal |
| 63 | 8 | 24 May 2025 | 2 Jun 2025 | 0.00 | Invoice |
| 64 | 4 | 29 Sep 2026 | 5 Oct 2026 | 4.90 | Invoice |
| 65 | 10 | 22 Jan 2026 | 27 Jan 2026 | 9.90 | Invoice |
| 66 | 9 | 27 Mar 2026 | 28 Mar 2026 | 9.90 | Credit card |
| 67 | 14 | 11 Sep 2026 | 18 Sep 2026 | 4.90 | PayPal |
| 68 | 4 | 9 Jun 2026 | 16 Jun 2026 | 0.00 | Invoice |
| 69 | 17 | 10 Jan 2026 | 17 Jan 2026 | 9.90 | Credit card |
| 70 | 21 | 1 Apr 2026 | 2 Apr 2026 | 4.90 | Credit card |
| 71 | 15 | 19 Mar 2025 | 21 Mar 2025 | 4.90 | Credit card |
| 72 | 20 | 4 Mar 2025 | 6 Mar 2025 | 4.90 | Invoice |
| 73 | 10 | 24 May 2025 | 9.90 | PayPal | |
| 74 | 8 | 3 Jan 2025 | 4 Jan 2025 | 9.90 | Invoice |
| 75 | 23 | 30 Oct 2025 | 6 Nov 2025 | 9.90 | Direct debit |
| 76 | 22 | 30 Aug 2025 | 3 Sep 2025 | 6.90 | Invoice |
| 77 | 2 | 18 Nov 2025 | 23 Nov 2025 | 6.90 | PayPal |
| 78 | 3 | 22 Dec 2025 | 26 Dec 2025 | 4.90 | Invoice |
| 79 | 21 | 26 May 2026 | 6.90 | Invoice | |
| 80 | 24 | 23 Feb 2026 | 27 Feb 2026 | 4.90 | Direct debit |
| 81 | 2 | 5 Jun 2026 | 6.90 | PayPal | |
| 82 | 11 | 14 Aug 2026 | 6.90 | Invoice | |
| 83 | 21 | 10 May 2026 | 18 May 2026 | 9.90 | Credit card |
| 84 | 13 | 12 Feb 2025 | 19 Feb 2025 | 4.90 | Credit card |
| 85 | 2 | 22 Jan 2026 | 30 Jan 2026 | 4.90 | PayPal |
| 86 | 2 | 31 Oct 2025 | 4 Nov 2025 | 9.90 | Credit card |
| 87 | 6 | 9 Mar 2025 | 17 Mar 2025 | 9.90 | Credit card |
| 88 | 3 | 5 Feb 2025 | 14 Feb 2025 | 9.90 | Direct debit |
| 89 | 17 | 26 Jan 2025 | 29 Jan 2025 | 6.90 | PayPal |
| 90 | 11 | 25 Sep 2026 | 4.90 | Direct debit | |
| 91 | 22 | 23 May 2025 | 1 Jun 2025 | 4.90 | Credit card |
| 92 | 20 | 29 Jan 2025 | 2 Feb 2025 | 0.00 | PayPal |
| 93 | 8 | 16 Jul 2026 | 18 Jul 2026 | 6.90 | Invoice |
| 94 | 2 | 7 Aug 2025 | 10 Aug 2025 | 0.00 | Invoice |
| 95 | 22 | 6 Jan 2025 | 8 Jan 2025 | 6.90 | Credit card |
| 96 | 15 | 15 Dec 2025 | 24 Dec 2025 | 4.90 | Invoice |
| 97 | 6 | 23 Sep 2025 | 30 Sep 2025 | 6.90 | Invoice |
| 98 | 10 | 10 Sep 2025 | 16 Sep 2025 | 0.00 | Invoice |
| 99 | 14 | 10 Jan 2026 | 13 Jan 2026 | 9.90 | Credit card |
| 100 | 16 | 20 Nov 2025 | 24 Nov 2025 | 0.00 | Credit card |
| 101 | 18 | 26 Jul 2026 | 27 Jul 2026 | 4.90 | Credit card |
| 102 | 2 | 15 May 2025 | 9.90 | Invoice | |
| 103 | 4 | 8 Feb 2025 | 15 Feb 2025 | 6.90 | Credit card |
| 104 | 7 | 16 Sep 2026 | 17 Sep 2026 | 4.90 | Invoice |
| 105 | 7 | 26 Jan 2025 | 31 Jan 2025 | 4.90 | Direct debit |
| 106 | 23 | 2 Aug 2026 | 3 Aug 2026 | 6.90 | Direct debit |
| 107 | 13 | 22 Jan 2026 | 26 Jan 2026 | 9.90 | Credit card |
| 108 | 4 | 6 Oct 2025 | 14 Oct 2025 | 4.90 | Direct debit |
| 109 | 10 | 6 Nov 2025 | 9 Nov 2025 | 4.90 | Direct debit |
| 110 | 9 | 17 Oct 2026 | 18 Oct 2026 | 9.90 | PayPal |
| 111 | 23 | 24 May 2026 | 25 May 2026 | 6.90 | Direct debit |
| 112 | 2 | 31 Aug 2025 | 1 Sep 2025 | 9.90 | Direct debit |
| 113 | 20 | 25 Jul 2026 | 28 Jul 2026 | 0.00 | Direct debit |
| 114 | 6 | 24 Nov 2025 | 27 Nov 2025 | 9.90 | Credit card |
| 115 | 8 | 27 Nov 2025 | 30 Nov 2025 | 6.90 | Credit card |
| 116 | 1 | 18 Mar 2025 | 25 Mar 2025 | 0.00 | Direct debit |
| 117 | 9 | 16 Mar 2025 | 19 Mar 2025 | 6.90 | Credit card |
| 118 | 4 | 10 Jul 2026 | 15 Jul 2026 | 0.00 | Invoice |
| 119 | 14 | 23 Jun 2025 | 28 Jun 2025 | 4.90 | Direct debit |
| 120 | 2 | 21 Sep 2026 | 27 Sep 2026 | 4.90 | Direct debit |
The arguments
| Argument | Example | means |
|---|---|---|
| TransferType | acImport (0), acExport (1), acLink (2) | read in, write out, link |
| SpreadsheetType | acSpreadsheetTypeExcel12Xml (10) | Excel workbook .xlsx |
| TableName | "Categories" | table or query |
| FileName | "C:\Data\List.xlsx" | file with path |
| HasFieldNames | True | first row holds field names |
Importing into an existing table
If the table exists, Access appends the rows; the headings in Excel must match the fields. If it does not exist, Access creates it: columns with numbers become Number fields (type Double), the rest text fields. Access assigns AutoNumbers itself.
Task A colleague keeps new categories in Excel: C:\Data\New categories.xlsx with the column Category. Write the procedure ImportCategories: it appends the rows to the Categories table.
Categories 4 rows, 2 columns
| CategoryID | Category |
|---|---|
| 1 | Office |
| 2 | Tech |
| 3 | Furniture |
| 4 | Paper |
This exercise is part of Premium.
Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.
See Premium Already Premium? Log in
The first exercise in this lesson is free.
In real Access
- Once, without code: the External Data tab, Excel under Import or Export. The wizard asks for the file, the target table and whether the first row holds field names.
- Regularly: a procedure with TransferSpreadsheet in a standard module, started from a button or a macro with RunCode.
- Text files (CSV) go through DoCmd.TransferText. Where the comma is the decimal separator, as in German regional settings, an import with commas between fields needs an import specification; otherwise Access reports 3441 because the field delimiter matches the decimal separator.
Common mistakes
File not found
If the file is missing, Access reports 3011 (“… could not find the object '…'”). If even the folder does not exist, it reports 3044 “'…' is not a valid path.”
Heading does not match the field
When appending, every column heading must match a field of the table. Rename the column in Excel, or import into a new table first and then append with an append query.
FAQ
Import or link?
An import copies the data once. With acLink the Excel file stays the source and Access reads it on every access; you cannot edit linked Excel data in Access.
Can I import just part of a sheet?
Yes, with the Range argument, such as "Sheet1!A1:C50".