Застрял Inte rnet Explorer Explorer автоматизации в VBA для расчета расстояния между двумя местами с помощью Google Map - PullRequest
0 голосов
/ 04 марта 2020
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

1 Ответ

0 голосов
/ 05 марта 2020

Вы можете установить значения начальной точки и пункта назначения, чтобы получить маршрут и расстояние. Пожалуйста, проверьте мой образец ниже:

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

Результат таков: https://imgur.com/1JFk7l3

...