Manipulation de chaîne et UTF-8

Bonjour,

BigDams m'a gentiment aidé (il a tout fait) pour que je puisse créer un XML à partir d'un tableau Excel.

Voici le code :

Sub generateXMLFile_simple()
Dim numfile As Integer
numfile = FreeFile
Open "c:\test2.xml" For Output As #numfile
Print #numfile, "<LISTE>"
i = 2
While Cells(i, 1) <> ""
    Print #numfile, "<Fiche id=" & i & " NOM=" & Cells(i, 1) & " PRENOM=" & Cells(i, 2) & " ADRESSE=" & Cells(i, 3) & "/>"
    i = i + 1
Wend

Print #numfile, "</LISTE>"
Close #numfile

End Sub

Un problème demeure : l'encodage en UTF-8 .... car les accents et autres caractères spéciaux ne passent pas ...

Quelqu'un pourrait-il m'aider ?

Par avance merci

Bonjour Albert34

Essaye peut-être avec ce code modifié pour tes besoins

Sub GenerateXMLFile_UTF8()
  Dim objStream As Object
  Dim I As Long
  '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"
  objStream.WriteText "<LISTE>"
  I = 2
  While Cells(I, 1) <> ""
    'Write to the steam
    objStream.WriteText "<Fiche id=" & I & " NOM=" & Cells(I, 1) & " PRENOM=" & Cells(I, 2) & " ADRESSE=" & Cells(I, 3) & "/>"
    I = I + 1
  Wend
  objStream.WriteText "</LISTE>"
  'Save the stream to a file
  objStream.SaveToFile "c:\test2.xml"
End Sub

A+

Merci, mais la macro ne veut pas s'exécuter, j'ai un message d'erreur : " Un composant ActiveX ne peut créer d'objet"

Au déboguage il me surligne :

Set objStream = CreateObject("ADODB.Stream")

Encore un problème de composant non installé (lequel ?) ... un problème sur Mac ?

Merci

Malheureusement, j'ai une réponse qui n'en est pas une :

Anywhoo, after moving to the Mac I realized to my dismay that ADODB.Stream is not available. Which makes sense, as it is an Active X.

et que j'ai trouvée ici : https://talesoftech.blogspot.fr/2011/05/excel-on-mac-goodbye-vba-hello.html

Pas d'ActiveX sur Mac donc pas de "ADODB.Stream" ....

Y a t'il moyen de contourner cela ?

Rechercher des sujets similaires à "manipulation chaine utf"