VBA & Macro Problems

How to Merge Multiple CSV Files in Microsoft Access Using VBA

Emma BrownEmma Brown Oct 26, 2026 868 views

Question details

The user wants to combine multiple CSV files from a specific folder into a single destination using a VBA script triggered by a Microsoft Access form button.

How to Merge Multiple CSV Files in Microsoft Access Using VBA
Product
Microsoft Access
Device & OS
not provided
Scenario
Automating the consolidation of multiple CSV files from a directory into a single table or workbook using Microsoft Access VBA.
Observed behavior
Using Excel-specific VBA objects like 'Workbooks' directly in Access VBA causes errors because these objects are not natively available in Access without explicit Excel automation.
Before you start

Before running any VBA scripts, ensure that all source CSV files share the exact same column structure and headers, and verify whether your final goal is to store the merged data natively in an Access table or in an external Excel workbook.

Solution 1Recommended

Import and Append CSV Files to an Access Table

Use this method if you want to store the combined CSV data natively within a Microsoft Access database table.

This approach uses Data Access Objects (DAO) and the DoCmd.TransferText method to loop through a folder and append each CSV file into an existing Access table.

1
Prepare the Destination Table

Create a new table in Microsoft Access with field names and data types that exactly match the structure of your incoming CSV files.

2
Open the VBA Editor

Press ALT + F11 to open the VBA Editor, then click on 'Insert' and select 'Module' to create a new script area.

3
Write the Loop Script

Write a VBA script using the Dir() function to iterate through the specific folder containing your source CSV files.

4
Execute the TransferText Command

Within your loop, use the 'DoCmd.TransferText acImportDelim' command to append the current CSV file's data into your prepared destination table.

Import and Append CSV Files to an Access Table
Preventing Duplicates: If you want to prevent duplicate records during the import, ensure your Access destination table has a Primary Key defined that matches unique identifiers in your CSV data.
Free Microsoft Office alternative

Handle CSV Data Seamlessly with WPS Office

While Microsoft Access requires complex automation to output merged CSVs to Excel, WPS Office provides a robust, lightweight alternative for managing spreadsheet data. WPS Spreadsheets fully supports VBA macros, allowing you to easily merge and manipulate CSV files directly without the steep licensing costs of Microsoft Office.

Fully compatible with Microsoft Excel formats including .xlsx, .xls, and .csv.Built-in VBA macro support for automating repetitive data tasks.Lightweight software that runs smoothly on various operating systems.Free to download and use with a highly familiar user interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get an 'Object Required' error when using Workbooks in Access VBA?

This error occurs because 'Workbooks' is an Excel-specific object. To use it in Access VBA, you must first create an Excel Application object (known as Excel Automation) and reference the workbook through that application instance.

Do all CSV files need to have the same headers to be merged?

Yes, for a seamless merge using VBA—whether appending to an Access table or copying to a master Excel sheet—all source CSV files should ideally have an identical column structure. Otherwise, your data fields will become misaligned.

How can I remove duplicate records when merging CSV files?

If you are importing into an Access table, setting a Primary Key will automatically reject duplicate entries. In Excel, you can utilize the 'RemoveDuplicates' method in your VBA script after all data has been merged into the master workbook.