在vba中使用Internet explorer automation使用google地图计算两个地方之间的距离

在vba中使用Internet explorer automation使用google地图计算两个地方之间的距离,vba,internet-explorer,Vba,Internet Explorer,可以设置起点和终点的值以获取路线和距离。请检查以下我的样本: Sub Automate_IE_Load_Page() Dim i As Long Dim URL As String Dim IE As Object Dim objElement As Object Dim objCollection As Object Set IE = CreateObject("InternetExplorer.Application") IE.Vis

可以设置起点和终点的值以获取路线和距离。请检查以下我的样本:

Sub Automate_IE_Load_Page()
    Dim i As Long
    Dim URL As String
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    URL = "https://www.google.com/maps"
    IE.Navigate URL
    Application.StatusBar = URL & " is loading. Please wait..."
    Do While IE.ReadyState = 4: DoEvents: Loop   'Do While
    Do Until IE.ReadyState = 4: DoEvents: Loop   'Do Until
    Application.StatusBar = URL & " Loaded"

   IE.document.getElementById("searchbox-directions").Click
结果如下:

Sub Automate_IE_Load_Page()
    Dim i As Long
    Dim URL As String
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    URL = "https://www.google.com/maps"
    IE.Navigate URL
    Application.StatusBar = URL & " is loading. Please wait..."
    Do Until IE.readyState = 4
       DoEvents
    Loop
    Application.StatusBar = URL & " Loaded"

   IE.document.getElementById("searchboxinput").Value = "Lincoln Park, Chicago, IL" 'set the destination
   IE.document.getElementById("searchbox-directions").Click

   IE.document.getElementsByClassName("tactile-searchbox-input")(2).Value = "Chicago, Illinois" 'set the start point
   Application.SendKeys "{ENTER}"
   IE.document.getElementsByClassName("searchbox-searchbutton")(2).Click
End Sub