Bonjour,

J'accède depuis vba à la page web cartographie du Morbihan.
Je décode cette page à la recherche des noms de zones, et je tombe sur ""Pays d’Auray", pour "Pays d'Auray".
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
        <area shape="poly" coords="305,84,336,33,425,73,391,97,443,136,438,159,391,163,410,184,383,191,366,175,325,190"
 href="../cistesParZone.php?idRegion=14&codeZone=3" alt="Pays de Ploërmel"
        onmouseover="
          document.images['myimagemap'].src=MesImages[3].src;
          document.body.style.cursor='pointer';" 
          />
          <area shape="poly" coords="205,166,200,196,223,193,222,217,196,230,220,366,156,381,104,349,148,302,130,233,170,163,197,150"
 href="../cistesParZone.php?idRegion=14&codeZone=7" alt="Pays d’Auray"
        onmouseover="
          document.images['myimagemap'].src=MesImages[7].src;
          document.body.style.cursor='pointer';"
          />

En vba je récupère le texte, mais dans mon code je ne retrouve pas "Pays d’Auray" mais "Pays dâ??Auray".
Du coup le décodage UTF8 ne donne rien, je conserve "Pays dâ??Auray".
Et si je veux remplacer dâ?? par d' j'obtiens toujours dâ

Plus haut on trouve "Pays de Ploërmel", là le decodage UTF8 marche bien.

DecodeUTF8 est fourni par BILLOT Michel. J'ai codé un autre module pour décoder UTF8 : RemplaceUTF mais le résultat est idem.

Qui peut m'expliquer ce qui cloche, et comment je m'en sors.
Merci.

Code vba : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Sub DecodeUrl()
Dim l_Url As String
Dim tArea(50) As String, tZone(50) As String, nbZone As Integer
Dim texte As String, noDept As String, txt As String
Dim area As String, zone As String
Dim i As Long, j As Long, k As Long
 
 
    [A1] = "56"
    noDept = [A1]
    l_Url = "http://s599720764.onlinehome.fr/cartocistes/cartographie" & noDept & "/indexOrdi.php?codeRegion=" & noDept & "&codePays=FR"
    texte = GetCodeSource(l_Url)    'avec les balises(format html)
 
' Boucle recherche <area shape="poly" coords=
    j = 1
    Do
        j = InStr(j, texte, "<area shape=""poly"" coords=")
        If j = 0 Then Exit Do
        txt = Mid(texte, j, 200)
        j = j + Len("<area shape=""poly"" coords=") + 1
        k = InStr(j, texte, """")
        If k > 0 Then
            txt = Mid(texte, k, 50) 'Sauter jusqu'à la 1ère zone
            If InStr(1, txt, "href") Then
                nbZone = nbZone + 1
                area = Mid(texte, j, k - j)
                tArea(nbZone) = area
        ' Recherche alt= pour nom de la zone
                j = k
                j = InStr(j, texte, "alt=")
                If j > 0 Then
                    j = j + 5
                    k = InStr(j, texte, """")
                    If k > 0 Then
                        zone = Mid(texte, j, k - j)
            ' Pour debug
                        Range("B" & nbZone) = zone
''                        Range("G" & nbZone) = DecodeUTF8(zone)
                        Range("G" & nbZone) = RemplaceUTF(zone)
                    End If
                End If
            End If
        End If
    Loop While j > 0
 End Sub
Function RemplaceUTF(ByVal chaine As String) As String
ReDim a_remplacer(0 To 29)
ReDim remplacants(0 To 29)
Dim i As Byte
a_remplacer = Array("î", "é", "→", "Ü", "ù", "â", "è", "à ", "’", "€", "®", "Ø", "°", "ç", "ô", _
                  "«", "»", "û", "ê", "…", "/ø", "ø", "À", "É", "È", " à ", "Ö", "ë", "â??")
remplacants = Array("î", "é", Chr(26), "Ü", "û", "â", "è", "à", "'", "€", "®", "Ø", "°", "ç", "ô", _
                  Chr(34), Chr(34), "û", "ê", "..", "ø", "ø", "A", "E", "E", " à ", "Ö", "ë", "d'")
For i = 0 To 28
    chaine = Replace(chaine, a_remplacer(i), remplacants(i))
Next i
    RemplaceUTF = chaine
End Function
 
Public Function GetCodeSource(sURL)
Dim Lapage_en_HTML         'variable pour l'object "Microsoft.XMLHTTP"( l'object XML)
    Set Lapage_en_HTML = CreateObject("Microsoft.XMLHTTP")    'instancie l'object
    Lapage_en_HTML.Open "GET", sURL    'ouvre l'url dans l'object
    Lapage_en_HTML.Send
    Do: DoEvents: Loop While Lapage_en_HTML.ReadyState <> 4    'attendre que la page soit chargée
 
    'le code source est dans """"Lapage_en_HTML.ResponseText""""
    'on créé un object "htmlfile"
    With CreateObject("htmlfile")
        'on y ecrit le codesource complet
        .Write Lapage_en_HTML.ResponseText
    End With
    GetCodeSource = Lapage_en_HTML.ResponseText
End Function