How to Save an Excel File as a Windows CSV Using VBA
Question details
The user needs to automate saving an Excel workbook explicitly into the standard Windows CSV format instead of the UTF-8 CSV format using a VBA macro.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Automating the data export process using VBA where the output file strictly requires Windows CSV format encoding for compatibility with specific downstream applications.
- Observed behavior
- The goal is to correctly use the xlCSVWindows file format constant in the SaveAs method to enforce the proper encoding during the automated save process.
Ensure that the data you intend to export is located on the currently active worksheet, as the CSV file format cannot support multiple sheets. Make sure the Developer tab is enabled in your ribbon so you can access the Visual Basic editor.
Use the VBA SaveAs Method with the xlCSVWindows Constant
You can explicitly declare the export format in your VBA macro by setting the FileFormat argument of the SaveAs method to xlCSVWindows.
By default, standard SaveAs commands might rely on system locale defaults or save as a modern UTF-8 CSV. If you are interacting with legacy software that explicitly requires the standard Windows ANSI comma-separated format, forcing the xlCSVWindows constant ensures exact compatibility without manual intervention.
In your open workbook, navigate to the Developer tab and click on 'Visual Basic', or simply press ALT + F11 on your keyboard to launch the VBA editor.
Right-click on your workbook name in the Project Explorer window on the left, select 'Insert', and then click 'Module' to create a blank script window.
Type the macro code utilizing the xlCSVWindows parameter. For example: ActiveWorkbook.SaveAs Filename:="C:\YourDirectory\YourFileName.csv", FileFormat:=xlCSVWindows. You can replace the directory path with 'Selection' or a dynamic path variable if needed.
Click anywhere inside your newly written code and press F5, or click the green 'Run' arrow in the toolbar, to execute the script and generate your Windows CSV file.

Automate Data Exports Easily with WPS Spreadsheet
WPS Spreadsheet features robust built-in support for VBA and macros, allowing you to run your existing Excel VBA scripts without needing to rewrite them. You can effortlessly automate your CSV exports and manage advanced data processing for free.
- 1. Open Your Workbook in WPS Spreadsheet: Launch WPS Office, open the Spreadsheet application, and load your existing workbook containing the data to be exported.
- 2. Access the Developer Tools: Click on the 'Tools' tab in the top ribbon and select 'Developer' to reveal the advanced macro options.
- 3. Open the Visual Basic Editor: Click the 'Visual Basic Editor' icon or press ALT + F11 to open the macro coding environment.
- 4. Paste and Run Your Script: Paste your SaveAs code using the xlCSVWindows file format argument and execute the code to seamlessly save your Windows CSV file.

Frequently Asked Questions
What is the difference between xlCSVWindows and xlCSVUTF8?
The xlCSVWindows constant saves the file using the standard Windows ANSI encoding (such as Windows-1252), which is often required by older Windows databases or legacy applications. In contrast, xlCSVUTF8 uses UTF-8 encoding, which supports a wider array of global characters and special symbols, making it the preferred standard for modern web and international applications.
Can I save multiple worksheets into a single CSV file using VBA?
No, the CSV file architecture is flat and does not support multiple sheets or tabs. Running a SaveAs command to a CSV format will only export the currently active worksheet. If you need to export multiple sheets, you must write a VBA loop to activate each sheet and save it as an individual CSV file.
How can I suppress the warning prompts when saving a file as CSV via VBA?
Because saving as a CSV removes formatting and formulas, the application naturally prompts a warning. You can suppress these alerts by adding the line Application.DisplayAlerts = False at the beginning of your macro, and setting it back to True at the end of the script after the SaveAs command.
How do I let the user choose the file name and location when exporting to CSV?
Instead of hardcoding the file path, you can use the Application.GetSaveAsFilename method in VBA. This triggers the standard 'Save As' dialog box, allowing the user to select their desired folder and file name. You can then pass the user's selected path into your SaveAs Filename parameter.




