IPB

Bienvenue invité ( Connexion | Inscription )

> Conversion Excel Win vers Mac, Aide en vba
Options
m00n
posté 16 Jun 2019, 10:02
Message #1


Macbidouilleur de bronze !
**

Groupe : Membres
Messages : 391
Inscrit : 2 Jun 2006
Membre no 62 332



Hello tout le monde,

J'ai trouvé une fonction en vba sur le net qui calcule grâce à Google Maps la distance entre deux villes. Mais, elle requiert Microsoft XML v6.0 qui ne peut pas être installé sur un Mac. Voici la fonction :

Code
Function G_DISTANCE(Origin As String, Destination As String) As Double
' Requires a reference to Microsoft XML, v6.0
' Draws on the stackoverflow answer at bit.ly/parseXML
Dim myRequest As XMLHTTP60
Dim myDomDoc As DOMDocument60
Dim distanceNode As IXMLDOMNode
    G_DISTANCE = 0
    ' Check and clean inputs
    On Error GoTo exitRoute
    Origin = WorksheetFunction.EncodeURL(Origin)
    Destination = WorksheetFunction.EncodeURL(Destination)
    ' Read the XML data from the Google Maps API
    Set myRequest = New XMLHTTP60
    myRequest.Open "GET", "http://maps.googleapis.com/maps/api/directions/xml?origin=" _
        & Origin & "&destination=" & Destination & "&sensor=false", False
    myRequest.send
    ' Make the XML readable usign XPath
    Set myDomDoc = New DOMDocument60
    myDomDoc.LoadXML myRequest.responseText
    ' Get the distance node value
    Set distanceNode = myDomDoc.SelectSingleNode("//leg/distance/value")
    If Not distanceNode Is Nothing Then G_DISTANCE = distanceNode.Text / 1000
exitRoute:
    ' Tidy up
    Set distanceNode = Nothing
    Set myDomDoc = Nothing
    Set myRequest = Nothing
End Function

Est-ce que l'un d'entre vous, doué en vba, pourrait convertir cette fonction pour qu'elle tourne sous excel Mac (office 2011 ou 2016) ?
Merci d'avance.

m00n


--------------------
MacBook Pro (15-inch, Late 2016), 2,9 GHz Intel Core i7, 16 Go 2133 MHz LPDDR3
Go to the top of the page
 
+Quote Post
 
Start new topic
Réponse(s)
m00n
posté 16 Jun 2019, 16:37
Message #2


Macbidouilleur de bronze !
**

Groupe : Membres
Messages : 391
Inscrit : 2 Jun 2006
Membre no 62 332



Ok merci Aliboron.

Si ce n'est pas trop te demander, puisqu'il semble que tu aies windows 10, pourrais-tu tester la fonction ci-dessous, qui normalement fait la même chose que celle de mon premier post. Fonctionne-t-elle ? Est-elle adaptable ? Merci beaucoup.

Code
Function distancier_google(start, dest)
'creation d'un object xmldoc en memoire
    Set xmldoc = CreateObject("Microsoft.XMLDOM")
    xmldoc.Async = "false"
    'creation de l'url avec les arguments
    URL = "https://maps.googleapis.com/maps/api/distancematrix/xml?origins=" & start & "&destinations=" & dest & "&language=fr-FR"
    xmldoc.Load (URL)    'load de l'url dans le xmldoc
    'Debug.Print xmldoc.XML
    'examen du fichier en DOM
    For Each Distances In xmldoc.SelectNodes("/DistanceMatrixResponse")
        Status = Distances.SelectSingleNode("status").Text
        If Status = "OK" Then
            depart = Distances.SelectSingleNode("origin_address").Text
            Debug.Print depart
            Arrivee = Distances.SelectSingleNode("destination_address").Text
            Debug.Print Arrivee
            For Each Row In xmldoc.SelectNodes("/DistanceMatrixResponse/row/element")
                Status = Row.SelectSingleNode("status").Text
                If Status = "OK" Then
                    'on imbrique 2 boucles "la distance" et le "temps"
                    For Each Distance In xmldoc.SelectNodes("/DistanceMatrixResponse/row/element/distance")
                        En_M = Distance.SelectSingleNode("value").Text
                        Debug.Print En_M & " metres"
                        En_KM = Distance.SelectSingleNode("text").Text
                        Debug.Print En_KM & " kilomètres"
                        For Each Duration In xmldoc.SelectNodes("/DistanceMatrixResponse/row/element/duration")
                            En_SS = Duration.SelectSingleNode("value").Text
                            Debug.Print En_SS; " secondes"
                            En_MM = Duration.SelectSingleNode("text").Text
                            Debug.Print En_MM
                        Next

                    Next
                Else
                End If
            Next
        Else
        End If
    Next
        Set xmldoc = Nothing

End Function


--------------------
MacBook Pro (15-inch, Late 2016), 2,9 GHz Intel Core i7, 16 Go 2133 MHz LPDDR3
Go to the top of the page
 
+Quote Post

Les messages de ce sujet


Reply to this topicStart new topic
1 utilisateur(s) sur ce sujet (1 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :

 



Nous sommes le : 18th July 2025 - 02:39