Export Excel Worksheet Data as UTF-8 Text with VBA on Mac
Question details
Export dynamically generated worksheet data to a UTF-8-encoded text file using VBA.

- 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.
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.
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.
In Excel 2011, open Tools > Macro > Visual Basic Editor, then select Insert > Module.
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
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.
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.

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.

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.




