VBA & Macro Problems

Copy an Excel Worksheet to a UTF-8 CSV File with VBA

Steve KSteve K Dec 2, 2026 869 views

Question details

Copy an Excel worksheet to a new workbook and export it as a UTF-8 CSV without renaming or modifying the original worksheet.

Copy an Excel Worksheet to a UTF-8 CSV File with VBA
Product
Microsoft Excel VBA
Device & OS
not provided
Scenario
A user wants to automate the export of one worksheet to a UTF-8 CSV file while keeping the source workbook unchanged.
Observed behavior
The copied worksheet is saved as a UTF-8 CSV, and the original worksheet remains in its original workbook without being renamed.
Before you start

Open the source workbook, save it to a writable local folder, and select the worksheet you want to export. Make sure your version of Excel supports the xlCSVUTF8 file format and that macros are enabled.

Solution 1Recommended

Copy the worksheet and save the new workbook as UTF-8 CSV

Use this VBA macro to export the active worksheet without renaming or editing the original.

Worksheet.Copy without a destination creates a new workbook. The macro saves and closes that new workbook, leaving the source worksheet in place.

CSV stores only one sheet's data, not workbook formatting, formulas, or other worksheets.

1
Open the VBA editor

In Excel, open the source workbook and select the worksheet to export. Open the VBA editor, then choose Insert > Module.

2
Add the export macro

Paste this code into the module: Sub ExportActiveSheetToUtf8Csv() Dim sourceSheet As Worksheet Dim exportBook As Workbook Dim outputPath As String Dim errorMessage As String On Error GoTo ExportFailed Set sourceSheet = ActiveSheet If sourceSheet.Parent.Path = "" Then MsgBox "Save the source workbook to a local folder first." Exit Sub End If outputPath = sourceSheet.Parent.Path & Application.PathSeparator & _ "export_" & Format(Now, "yyyymmdd_hhnnss") & ".csv" sourceSheet.Copy Set exportBook = ActiveWorkbook exportBook.SaveAs Filename:=outputPath, FileFormat:=xlCSVUTF8 exportBook.Close SaveChanges:=False MsgBox "CSV saved to: " & outputPath Exit Sub ExportFailed: errorMessage = Err.Description On Error Resume Next If Not exportBook Is Nothing Then exportBook.Close SaveChanges:=False On Error GoTo 0 MsgBox "Export failed: " & errorMessage End Sub

3
Run the macro

Return to Excel, select the worksheet to export, and run ExportActiveSheetToUtf8Csv from the Macros dialog. The CSV is saved in the source workbook's folder with a timestamped name.

Copy the worksheet and save the new workbook as UTF-8 CSV
Check the exported data: The CSV contains the copied sheet's exported values, not its formatting or formulas. Excel may prompt you if a file with the generated name already exists.
Free Microsoft Office alternative

Work with spreadsheet and CSV files in WPS Office

WPS Office is a free, lightweight alternative for everyday spreadsheet work. Its familiar interface and Microsoft Office format compatibility make it easy to move existing files, though it does not fix Excel-specific VBA issues.

Open and work with CSV spreadsheet dataCompatible with Microsoft Excel formats such as XLSX and XLSFamiliar spreadsheet interface for an easier transitionFree and lightweight for everyday Office tasks
QA img-9

Frequently Asked Questions

Does the macro rename or delete the original worksheet?

No. The Worksheet.Copy command creates a copy in a new workbook. The macro saves and closes that new workbook without renaming or deleting the source sheet.

Where is the UTF-8 CSV file saved?

The macro saves it in the source workbook's folder with a name beginning with export_ and followed by a timestamp. Save the source workbook to a writable local folder before running it.

Why does xlCSVUTF8 cause an error?

Your version of Excel may not support the xlCSVUTF8 file format. Check your Excel version and update it if necessary, or use another UTF-8 export method.

Will the CSV retain formulas and formatting?

No. CSV is a plain-text format that stores the exported sheet's data, not Excel formulas, formatting, or additional worksheets.