Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 从XML获取数据_Vba_Excel_Xml Parsing - Fatal编程技术网

Vba 从XML获取数据

Vba 从XML获取数据,vba,excel,xml-parsing,Vba,Excel,Xml Parsing,大家好 在我的论文中,我正在用excel开发一个模型,用于计算卡车从仓库到客户的距离和行程时间。有了这个模型,我们可以对交通有一个很好的基本了解 我仍然在努力从XML文件中获取信息并将其放入excel中。我用VBA编写了以下脚本 Public Function G_Distance(startGPS As String, eindGPS As String) As Variant 'vervoer As String' Dim vehicletype As String Dim Apikey

大家好

在我的论文中,我正在用excel开发一个模型,用于计算卡车从仓库到客户的距离和行程时间。有了这个模型,我们可以对交通有一个很好的基本了解

我仍然在努力从XML文件中获取信息并将其放入excel中。我用VBA编写了以下脚本

Public Function G_Distance(startGPS As String, eindGPS As String) As Variant
'vervoer As String'

Dim vehicletype As String
Dim Apikey As String
Dim linkAPIkey As String
Dim linkstartGPS As String
Dim linkendGPS As String

Apikey = "&api_key=ee0b8233adff52ce9fd6afc2a2859a28"
linkstartGPS = "&start=" & startGPS
linkendGPS = "&end=" & eindGPS
vehicletype = "&"

''' Link put location to KM'''
Language = "&lang=en"
Maxresponseamount = "&MaxResponse=1"
Distanceunits = "&distunit=KM"

Dim IE As New InternetExplorer
IE.Visible = True


IE.navigate "http://openls.geog.uni-heidelberg.de/route?
&routepref=HeavyVehicle" & linkstartGPS & linkendGPS & Language & 
Maxresponseamount & Distanceunits & Apikey
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE

Dim doc As HTMLDocument
Set doc = IE.document
Dim sDD As String
sDD = Trim(doc.getElementsByTagName("xls:TotalDistance value").innerText)



G_Distance = sDD


End Function
因此,这个脚本的作用是将出发点的GPS位置和目的地的GPS位置放入两个不同的单元格(A2和B2)。要启动您使用的函数:=G_距离(A2;B2)

当您启动此函数时,它将打开一个资源管理器,在这里您将看到包含距离的XML文件。现在唯一不起作用的部分是将数据从XML中提取到excel中

我希望你们能帮我

您好, Jelle

使用MSXML代替IE:使用MSXML代替IE: