The Problem (Q-score 9, ranked #54th of 303 in the Excel VBA archive)
The scenario as originally posted in 2013
I am trying to generate a CSV file on the client side using javascript. I’ve followed the answer on this stackoverflow question. I have unicode characters in the content (Hebrew characters in my case).
The file generation succeeds, however when I open the file in Excel – all the unicode characters are shown as funny characters. ASCII characters (English and numbers) are presented well.
The weird thing is that if I open the file in notepad, the unicode characters show well. So I guess this has something to do with Excel and the way I’m saving the file.
Any ideas?
Why community consensus is tight on this one
Across 303 Excel VBA entries in the archive, the accepted answer here holds strong answer (top 25 %%) status — meaning voters are unusually aligned on the right fix.
The Verified Solution — strong answer (top 25 %%) (+21)
7-line Excel VBA pattern (copy-ready)
Following Jack Cole’s comment and this question, what fixed my problem was adding a BOM prefix (uFEFF) to the beginning of the file.
This is the working code:
var csvContent = "...csv content...";
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", "data:text/csv;charset=utf-8,uFEFF" + encodedUri);
link.setAttribute("download","report.csv");
link.click();
When to Use It — classic (2013–2016)
Ranked #54th in its category — specialized fit
This pattern sits in the 94% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the Excel VBA archive for a higher-consensus alternative.
What changed between 2013 and 2026
The answer is 13 years old. The Excel VBA object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.