Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save text file UTF-8 encoded with VBA

Tags:

utf-8

vba

how can I write UTF-8 encoded strings to a textfile from vba, like

Dim fnum As Integer fnum = FreeFile Open "myfile.txt" For Output As fnum Print #fnum, "special characters: äöüß" 'latin-1 or something by default Close fnum 

Is there some setting on Application level?

like image 310
Karsten W. Avatar asked Mar 26 '10 16:03

Karsten W.


People also ask

How do I save a file with encoding?

To save a file with encodingFrom the File menu, choose Save File As, and then click the drop-down button next to the Save button. The Advanced Save Options dialog box is displayed. Under Encoding, select the encoding to use for the file. Optionally, under Line endings, select the format for end-of-line characters.


1 Answers

I found the answer on the web:

Dim fsT As Object Set fsT = CreateObject("ADODB.Stream") fsT.Type = 2 'Specify stream type - we want To save text/string data. fsT.Charset = "utf-8" 'Specify charset For the source text data. fsT.Open 'Open the stream And write binary data To the object fsT.WriteText "special characters: äöüß" fsT.SaveToFile sFileName, 2 'Save binary data To disk 

Certainly not as I expected...

like image 127
Karsten W. Avatar answered Sep 25 '22 04:09

Karsten W.