How to Automatically Update a CSV File from an Excel Workbook
Question details
The user wants to automatically update a saved CSV file whenever changes are made in the source Excel workbook.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Exporting data to a CSV for external uses like a mail merge that requires up-to-date information from a dynamic source workbook.
- Observed behavior
- CSV files are plain text and do not retain formulas or external links, meaning they remain static and do not automatically update when the original Excel workbook changes.
Ensure that your spreadsheet program has Developer tools enabled, as automatically exporting data to a CSV requires running a background VBA script.
Use a VBA Macro to Auto-Export CSV on Save
Use the Workbook_BeforeSave event to automatically generate and overwrite a specific CSV file every time you save your main Excel workbook.
Since CSV files are plain text, they cannot hold live formulas or maintain links to external workbooks. To keep a CSV updated with your latest calculations, you must actively re-export the data.
By using a short VBA script, you can automate this export process so that a fresh CSV is generated in the background whenever you save or close the master file.
Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor in your spreadsheet.
In the Project Explorer pane on the left, double-click on 'ThisWorkbook'.
Select 'Workbook' from the left dropdown menu and 'BeforeSave' from the right dropdown menu at the top of the code window.
Write the VBA code to copy your target worksheet, save it as a CSV format to your specified folder path, and close the newly created CSV to prevent prompt interruptions.
Return to your spreadsheet, go to File > Save As, and choose 'Excel Macro-Enabled Workbook (*.xlsm)' so your automation code runs in future sessions.
Keep Data in Excel for Direct Mail Merge
If you are using the CSV file strictly for a mail merge, you can bypass the CSV format entirely and connect your document directly to the Excel workbook.
Easily Automate CSV Exports and Data Merges in WPS Spreadsheet
WPS Office provides robust support for VBA macros and direct mail merge capabilities. Whether you need to script an automatic CSV export or link your spreadsheet directly to a WPS Writer document, you can accomplish it seamlessly.
- 1. Open Your Data File: Launch WPS Spreadsheet and open the master workbook containing your formulas and formatted data.
- 2. Enable Macros: Navigate to the 'Tools' tab and click on 'Macro' to open the fully featured VBA editor.
- 3. Insert Automation Script: Paste your BeforeSave script into the ThisWorkbook module to automate the generation of your CSV file.
- 4. Use Direct Mail Merge (Optional): Alternatively, open WPS Writer, go to the 'References' or 'Mailings' tab, and directly import your spreadsheet data as a live source.

Frequently Asked Questions
Why doesn't my CSV file update when the source Excel file changes?
A CSV (Comma Separated Values) file is a plain text file. It cannot store external data connections, live Excel formulas, or macros. It only captures a snapshot of the text values at the exact moment it was saved.
Can I link a CSV file to another Excel workbook?
You can import a CSV file into an Excel workbook using Power Query or the Data tab so that Excel refreshes the imported text when the CSV changes, but a CSV file itself cannot pull in data from an Excel workbook.
Is it possible to auto-export a CSV without writing VBA code?
No, spreadsheet software does not have a native toggle to automatically sync or continuously export a secondary CSV file upon saving. Without using a VBA macro like Workbook_BeforeSave, you must manually use File > Save As and select the CSV format each time your data updates.




