Data Import & Export

Export Excel Worksheet Data as UTF-8 Text with VBA on Mac

Steve KSteve K Nov 27, 2026 869 views

Question details

Export dynamically generated worksheet data to a UTF-8-encoded text file using VBA.

Export Excel Worksheet Data as UTF-8 Text with VBA on Mac
Product
Microsoft Excel 2011 for Mac
Device & OS
Mac; macOS version not provided
Scenario
A VBA macro generates worksheet data that needs to be written to a UTF-8 text file.
Observed behavior
Excel 2011 for Mac VBA does not provide a direct UTF-8 file-writing option.
Before you start

Confirm the worksheet name, data range, and absolute path of an existing writable output folder. In Terminal, run locale -a to check that a UTF-8 locale such as en_US.UTF-8 is available.

Solution 1Recommended

Copy the worksheet range and export it with a shell command

Use the Mac clipboard and pbpaste to write the copied range as text from an Excel 2011 VBA macro.

The example uses Excel 2011's MacScript function to launch a shell command. Copied worksheet cells are typically written as tab-delimited text, not as a formatted workbook.

1
Open the VBA editor

In Excel 2011, open Tools > Macro > Visual Basic Editor, then select Insert > Module.

2
Add the export macro

Paste the following code into the module: Sub ExportUtf8Text() ThisWorkbook.Worksheets("Sheet1").Range("A1:C10").Copy MacScript "do shell script ""export LC_ALL=en_US.UTF-8; /usr/bin/pbpaste > '/Users/yourname/Documents/export.txt'""" End Sub

3
Set the range and output path

Replace Sheet1 and A1:C10 with your generated data's sheet and range. Replace /Users/yourname/Documents/export.txt with an absolute path in an existing writable folder. Keep the single quotes around the path; the example requires a path without an apostrophe.

4
Run and check the export

Run ExportUtf8Text from the VBA editor. Open the resulting file in a UTF-8-aware text editor and check that non-ASCII characters and the expected rows and columns appear correctly.

Copy the worksheet range and export it with a shell command
Clipboard and file behavior: The macro replaces the current clipboard contents and overwrites an existing file at the specified path. Use a different filename if the existing file must be retained.
Free Microsoft Office alternative

Work with Excel data in WPS Spreadsheet

WPS Office is a free, lightweight Microsoft Office alternative with a familiar interface for opening and editing spreadsheets. Its Excel format support makes it easier to move existing files, although it does not fix the Excel 2011 VBA export workflow. Check system requirements before installing on a Mac.

Open and edit worksheet data in a familiar spreadsheet interfaceCompatible with Microsoft Excel formats such as XLSX and XLSFree, lightweight Office alternativeWork with existing spreadsheets without starting from scratch
microsoft office alternative - wps office

Frequently Asked Questions

What format does the clipboard export produce?

The copied Excel range is typically pasted as tab-delimited plain text, with rows separated by line breaks. It does not preserve workbook formatting, formulas, or multiple sheets.

Why does the command use an absolute file path?

The shell launched by MacScript may not use the folder you expect. Set the path in the pbpaste command to an absolute location, such as /Users/yourname/Documents/export.txt.

How can I check whether the exported text is valid UTF-8?

In Terminal, run iconv -f UTF-8 -t UTF-8 '/Users/yourname/Documents/export.txt' > /dev/null using your file path. A successful conversion indicates valid UTF-8, but you should also inspect non-ASCII characters in a text editor.

Can I use a different UTF-8 locale?

Yes. Run locale -a in Terminal and replace en_US.UTF-8 in the macro with an available UTF-8 locale if necessary.

Does this macro work in newer versions of Excel for Mac?

The example targets Excel 2011 for Mac. Newer versions have different automation and security restrictions, so MacScript and shell access may not work the same way.