Data Import & Export

How to Save an Excel File as a Windows CSV Using VBA

John WilsonJohn Wilson Oct 28, 2026 869 views

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.

How to Save an Excel File as a Windows CSV Using VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the Visual Basic Editor

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.

2
Insert a New Module

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.

3
Write the SaveAs Code

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.

4
Run the Macro

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.

Use the VBA SaveAs Method with the xlCSVWindows Constant
Alternative CSV FileFormat Constants: Depending on your specific target environment, VBA also supports xlCSV (the default based on the system locale), xlCSVMac (for Macintosh systems), xlCSVMSDOS (for legacy DOS applications), and xlCSVUTF8 (for broader international character support).
Advanced Macro Support in WPS

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. 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. 2. Access the Developer Tools: Click on the 'Tools' tab in the top ribbon and select 'Developer' to reveal the advanced macro options.
  3. 3. Open the Visual Basic Editor: Click the 'Visual Basic Editor' icon or press ALT + F11 to open the macro coding environment.
  4. 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.
High compatibility with Microsoft Excel VBA macro scripts (.xlsm)Accurately export data using exact file constants like xlCSVWindows and xlCSVUTF8Free, lightweight, and fast spreadsheet processingFamiliar user interface to ease your transition and macro management
QA img-9

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.