Ce mémo a été publié le 21 juin 2010 et peut contenir des informations qui peuvent être incomplètes, non mises à jour voir erronées du fait de son ancienneté.
N'hésitez pas à compléter votre recherche sur des articles plus récents.
Voici une fonction qui permet d’écrire un fichier texte en UTF-8.
Source : http://forum.hardware.fr/hfr/Programmation/VB-VBA-VBS/resolu-ecrire-utf-sujet_87311_1.htm
Par rapport à celle proposée dans la source, j’ai ajouté le retour chariot lors de l’écriture d’une ligne.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Private Sub CreateFile(ByVal pstrFile As String, ByVal pstrData As String) Dim objStream As Object 'Create the stream Set objStream = CreateObject("ADODB.Stream" ) 'Initialize the stream objStream.Open 'Reset the position and indicate the charactor encoding objStream.Position = 0 objStream.Charset = "UTF-8" 'Write to the steam objStream.WriteText pstrData & VbCrLf 'Save the stream to a file objStream.SaveToFile pstrFile End Sub |