使用VBA打开Chrome并填写表单

使用VBA打开Chrome并填写表单,vba,excel,Vba,Excel,我经常使用下面的网站追踪往返的航空里程。最近,该网站停止在IE中工作,所以我的代码也停止了。由于我在工作电脑上使用此功能,因此我无法下载搜索中找到的许多其他解决方案,并且如果不经过漫长的过程以获得网站批准,我无法使用其他网站。有没有办法在Chrome中执行相同的任务而不需要任何其他下载 Dim ele As Object Dim IE As New InternetExplorer IE.Visible = True IE.navigate "http://www.distancefromt

我经常使用下面的网站追踪往返的航空里程。最近,该网站停止在IE中工作,所以我的代码也停止了。由于我在工作电脑上使用此功能,因此我无法下载搜索中找到的许多其他解决方案,并且如果不经过漫长的过程以获得网站批准,我无法使用其他网站。有没有办法在Chrome中执行相同的任务而不需要任何其他下载

Dim ele As Object

Dim IE As New InternetExplorer
IE.Visible = True

IE.navigate "http://www.distancefromto.net"
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE

'step 1

With IE
.document.getElementsByName("distance")(0).Value = Range("B2").Value
.document.getElementsByName("distance")(1).Value = Range("B3").Value & Range("E3").Value
.document.getElementById("hae").Click

Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE

Application.Wait (Now + TimeValue("0:00:02"))

Dim a As String
a = Trim(.document.getElementById("totaldistancemiles").Value)
Dim aa As Variant
aa = Split(a, " ")
Range("C2").Value = aa(0)

'step 2

.document.getElementsByName("distance")(0).Value = Range("B4").Value & Range("E4").Value
.document.getElementById("hae").Click

Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE

Application.Wait (Now + TimeValue("0:00:02"))

Dim b As String
b = Trim(.document.getElementById("totaldistancemiles").Value)
Dim bb As Variant
bb = Split(b, " ")
Range("C3").Value = bb(0)

'step 3

.document.getElementsByName("distance")(1).Value = Range("B2").Value
.document.getElementById("hae").Click

Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE

Application.Wait (Now + TimeValue("0:00:02"))

Dim c As String
c = Trim(.document.getElementById("totaldistancemiles").Value)
Dim cc As Variant
cc = Split(c, " ")
Range("C4").Value = cc(0)


End With
IE.Quit
任何帮助,甚至是一个明确的“不,这不可能”都将得到极大的赞赏


谢谢你Chrome:

要使用Chrome-否。您需要下载或使用不同的编程语言,例如python

不同的站点:

你可以改用不同的网站(请注意,由于网站的原因,你之前的数据可能会有一些细微的差异,尽管从技术上讲,距离不应该有太大的变化!)。我注意到你说这会有问题。冒着听起来有点跟踪狂的风险,你以前用过,所以这可能是一个可以接受的选择

API:

如果你找到一个提供API服务的网站,你也许可以放弃上面的所有内容,发布一个新的API。我看不到你的网站提供API服务,否则这将是显而易见的下一个选择。 @RahulChalwa提到“[网站OP使用的本身就是围绕google maps API使用包装器:。用户可以注册API并进行POST请求]”;所以这可能是前进的方向。主要文件

例如API站点:个人和小规模使用API-

当前设置调试:

确定IE不再在您当前设置中工作的原因也是可取的,也许可以联系站点开发者并提出您的问题

使用哈弗森公式执行计算(如网站所做),或如其他网站所做,使用哈弗森公式执行计算:

哈弗森:

Vicenty's(包括示例代码):

维森蒂的密码来自。我已经归因于,但如果这不应该包括在这里,我将删除

'*************************************************************
Private Const PI = 3.14159265358979
Private Const EPSILON As Double = 0.000000000001

Public Function distVincenty(ByVal lat1 As Double, ByVal lon1 As Double, _
    ByVal lat2 As Double, ByVal lon2 As Double) As Double
'INPUTS: Latitude and Longitude of initial and 
'           destination points in decimal format.
'OUTPUT: Distance between the two points in Meters.
'
'======================================
' Calculate geodesic distance (in m) between two points specified by
' latitude/longitude (in numeric [decimal] degrees)
' using Vincenty inverse formula for ellipsoids
'======================================
' Code has been ported by lost_species from www.aliencoffee.co.uk to VBA
' from javascript published at:
' https://www.movable-type.co.uk/scripts/latlong-vincenty.html
' * from: Vincenty inverse formula - T Vincenty, "Direct and Inverse Solutions
' *       of Geodesics on the Ellipsoid with application
' *       of nested equations", Survey Review, vol XXII no 176, 1975
' *       https://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf
'Additional Reference: https://en.wikipedia.org/wiki/Vincenty%27s_formulae
'======================================
' Copyright lost_species 2008 LGPL 
' https://www.fsf.org/licensing/licenses/lgpl.html
'======================================
' Code modifications to prevent "Formula Too Complex" errors
' in Excel (2010) VBA implementation
' provided by Jerry Latham, Microsoft MVP Excel Group, 2005-2011
' July 23 2011
'======================================

  Dim low_a As Double
  Dim low_b As Double
  Dim f As Double
  Dim L As Double
  Dim U1 As Double
  Dim U2 As Double
  Dim sinU1 As Double
  Dim sinU2 As Double
  Dim cosU1 As Double
  Dim cosU2 As Double
  Dim lambda As Double
  Dim lambdaP As Double
  Dim iterLimit As Integer
  Dim sinLambda As Double
  Dim cosLambda As Double
  Dim sinSigma As Double
  Dim cosSigma As Double
  Dim sigma As Double
  Dim sinAlpha As Double
  Dim cosSqAlpha As Double
  Dim cos2SigmaM As Double
  Dim C As Double
  Dim uSq As Double
  Dim upper_A As Double
  Dim upper_B As Double
  Dim deltaSigma As Double
  Dim s As Double ' final result, will be returned rounded to 3 decimals (mm).
'added by JLatham to break up "Too Complex" formulas
'into pieces to properly calculate those formulas as noted below
'and to prevent overflow errors when using
'Excel 2010 x64 on Windows 7 x64 systems
  Dim P1 As Double ' used to calculate a portion of a complex formula
  Dim P2 As Double ' used to calculate a portion of a complex formula
  Dim P3 As Double ' used to calculate a portion of a complex formula

'See https://en.wikipedia.org/wiki/World_Geodetic_System
'for information on various Ellipsoid parameters for other standards.
'low_a and low_b in meters
' === GRS-80 ===
' low_a = 6378137
' low_b = 6356752.314245
' f = 1 / 298.257223563
'
' === Airy 1830 ===  Reported best accuracy for England and Northern Europe.
' low_a = 6377563.396
' low_b = 6356256.910
' f = 1 / 299.3249646
'
' === International 1924 ===
' low_a = 6378388
' low_b = 6356911.946
' f = 1 / 297
'
' === Clarke Model 1880 ===
' low_a = 6378249.145
' low_b = 6356514.86955
' f = 1 / 293.465
'
' === GRS-67 ===
' low_a = 6378160
' low_b = 6356774.719
' f = 1 / 298.247167

'=== WGS-84 Ellipsoid Parameters ===
  low_a = 6378137       ' +/- 2m
  low_b = 6356752.3142
  f = 1 / 298.257223563
'====================================
  L = toRad(lon2 - lon1)
  U1 = Atn((1 - f) * Tan(toRad(lat1)))
  U2 = Atn((1 - f) * Tan(toRad(lat2)))
  sinU1 = Sin(U1)
  cosU1 = Cos(U1)
  sinU2 = Sin(U2)
  cosU2 = Cos(U2)

  lambda = L
  lambdaP = 2 * PI
  iterLimit = 100 ' can be set as low as 20 if desired.

  While (Abs(lambda - lambdaP) > EPSILON) And (iterLimit > 0)
    iterLimit = iterLimit - 1

    sinLambda = Sin(lambda)
    cosLambda = Cos(lambda)
    sinSigma = Sqr(((cosU2 * sinLambda) ^ 2) + _
        ((cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) ^ 2))
    If sinSigma = 0 Then
      distVincenty = 0  'co-incident points
      Exit Function
    End If
    cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda
    sigma = Atan2(cosSigma, sinSigma)
    sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma
    cosSqAlpha = 1 - sinAlpha * sinAlpha

    If cosSqAlpha = 0 Then 'check for a divide by zero
      cos2SigmaM = 0 '2 points on the equator
    Else
      cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha
    End If

    C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha))
    lambdaP = lambda

'the original calculation is "Too Complex" for Excel VBA to deal with
'so it is broken into segments to calculate without that issue
'the original implementation to calculate lambda
'lambda = L + (1 - C) * f * sinAlpha * _
  (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * _
  (-1 + 2 * (cos2SigmaM ^ 2))))
      'calculate portions
    P1 = -1 + 2 * (cos2SigmaM ^ 2)
    P2 = (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * P1))
    'complete the calculation
    lambda = L + (1 - C) * f * sinAlpha * P2

  Wend

  If iterLimit < 1 Then
    MsgBox "iteration limit has been reached, something didn't work."
    Exit Function
  End If

  uSq = cosSqAlpha * (low_a ^ 2 - low_b ^ 2) / (low_b ^ 2)

'the original calculation is "Too Complex" for Excel VBA to deal with
'so it is broken into segments to calculate without that issue
  'the original implementation to calculate upper_A
  'upper_A = 1 + uSq / 16384 * (4096 + uSq * _
    (-768 + uSq * (320 - 175 * uSq)))
  'calculate one piece of the equation
  P1 = (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)))
  'complete the calculation
  upper_A = 1 + uSq / 16384 * P1

  'oddly enough, upper_B calculates without any issues - JLatham
  upper_B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)))

'the original calculation is "Too Complex" for Excel VBA to deal with
'so it is broken into segments to calculate without that issue
  'the original implementation to calculate deltaSigma
  'deltaSigma = upper_B * sinSigma * (cos2SigmaM + upper_B / 4 * _
    (cosSigma * (-1 + 2 * cos2SigmaM ^ 2) _
      - upper_B / 6 * cos2SigmaM * (-3 + 4 * sinSigma ^ 2) * _
        (-3 + 4 * cos2SigmaM ^ 2)))
  'calculate pieces of the deltaSigma formula
  'broken into 3 pieces to prevent overflow error that may occur in
  'Excel 2010 64-bit version.
  P1 = (-3 + 4 * sinSigma ^ 2) * (-3 + 4 * cos2SigmaM ^ 2)
  P2 = upper_B * sinSigma
  P3 = (cos2SigmaM + upper_B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM ^ 2) _
    - upper_B / 6 * cos2SigmaM * P1))
  'complete the deltaSigma calculation
  deltaSigma = P2 * P3

  'calculate the distance
  s = low_b * upper_A * (sigma - deltaSigma)
  'round distance to millimeters
  distVincenty = Round(s, 3)

End Function

Function SignIt(Degree_Dec As String) As Double
'Input:   a string representation of a lat or long in the
'         format of 10° 27' 36" S/N  or 10~ 27' 36" E/W
'OUTPUT:  signed decimal value ready to convert to radians
'
  Dim decimalValue As Double
  Dim tempString As String
  tempString = UCase(Trim(Degree_Dec))
  decimalValue = Convert_Decimal(tempString)
  If Right(tempString, 1) = "S" Or Right(tempString, 1) = "W" Then
    decimalValue = decimalValue * -1
  End If
  SignIt = decimalValue
End Function

Function Convert_Degree(Decimal_Deg) As Variant
'source: https://support.microsoft.com/kb/213449
'
'converts a decimal degree representation to deg min sec
'as 10.46 returns 10° 27' 36"
'
  Dim degrees As Variant
  Dim minutes As Variant
  Dim seconds As Variant
  With Application
     'Set degree to Integer of Argument Passed
     degrees = Int(Decimal_Deg)
     'Set minutes to 60 times the number to the right
     'of the decimal for the variable Decimal_Deg
     minutes = (Decimal_Deg - degrees) * 60
     'Set seconds to 60 times the number to the right of the
     'decimal for the variable Minute
     seconds = Format(((minutes - Int(minutes)) * 60), "0")
     'Returns the Result of degree conversion
    '(for example, 10.46 = 10° 27' 36")
     Convert_Degree = " " & degrees & "° " & Int(minutes) & "' " _
         & seconds + Chr(34)
  End With
End Function

Function Convert_Decimal(Degree_Deg As String) As Double
'source: https://support.microsoft.com/kb/213449
   ' Declare the variables to be double precision floating-point.
   ' Converts text angular entry to decimal equivalent, as:
   ' 10° 27' 36" returns 10.46
   ' alternative to ° is permitted: Use ~ instead, as:
   ' 10~ 27' 36" also returns 10.46
   Dim degrees As Double
   Dim minutes As Double
   Dim seconds As Double
   '
   'modification by JLatham
   'allow the user to use the ~ symbol instead of ° to denote degrees
   'since ~ is available from the keyboard and ° has to be entered
   'through [Alt] [0] [1] [7] [6] on the number pad.
   Degree_Deg = Replace(Degree_Deg, "~", "°")

   ' Set degree to value before "°" of Argument Passed.
   degrees = Val(Left(Degree_Deg, InStr(1, Degree_Deg, "°") - 1))
   ' Set minutes to the value between the "°" and the "'"
   ' of the text string for the variable Degree_Deg divided by
   ' 60. The Val function converts the text string to a number.
   minutes = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "°") + 2, _
             InStr(1, Degree_Deg, "'") - InStr(1, Degree_Deg, "°") - 2)) / 60
   ' Set seconds to the number to the right of "'" that is
   ' converted to a value and then divided by 3600.
   seconds = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "'") + _
           2, Len(Degree_Deg) - InStr(1, Degree_Deg, "'") - 2)) / 3600
   Convert_Decimal = degrees + minutes + seconds
End Function

Private Function toRad(ByVal degrees As Double) As Double
    toRad = degrees * (PI / 180)
End Function

Private Function Atan2(ByVal X As Double, ByVal Y As Double) As Double
 ' code nicked from:
 ' https://en.wikibooks.org/wiki/Programming:Visual_Basic_Classic
 '  /Simple_Arithmetic#Trigonometrical_Functions
 ' If you re-use this watch out: the x and y have been reversed from typical use.
    If Y > 0 Then
        If X >= Y Then
            Atan2 = Atn(Y / X)
        ElseIf X <= -Y Then
            Atan2 = Atn(Y / X) + PI
        Else
        Atan2 = PI / 2 - Atn(X / Y)
    End If
        Else
            If X >= -Y Then
            Atan2 = Atn(Y / X)
        ElseIf X <= Y Then
            Atan2 = Atn(Y / X) - PI
        Else
            Atan2 = -Atn(X / Y) - PI / 2
        End If
    End If
End Function
'======================================
'*************************************************************
私人常数PI=3.14159265358979
私有常量EPSILON为Double=0.000000000001
公共功能差异(ByVal lat1为双精度,ByVal lon1为双精度_
ByVal lat2为双精度,ByVal lon2为双精度)为双精度
'输入:初始值和初始值的纬度和经度
'十进制格式的目标点。
'输出:两点之间的距离,单位为米。
'
'======================================
'计算由指定的两点之间的测地距离(m)
'纬度/经度(以数字[十进制]度表示)
使用椭球体的Vincenty逆公式
'======================================
“代码已由lost_物种从www.aliencoffee.co.uk移植到VBA
'来自javascript,发布于:
' https://www.movable-type.co.uk/scripts/latlong-vincenty.html
'*摘自:Vincenty逆公式-T Vincenty,“正解和逆解
椭球面上测地线的“*”及其应用
“*嵌套方程”,调查综述,第二十二卷第176期,1975年
' *       https://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf
“附加参考:https://en.wikipedia.org/wiki/Vincenty%27s_formulae
'======================================
“版权已丢失”2008 LGPL
' https://www.fsf.org/licensing/licenses/lgpl.html
'======================================
'代码修改以防止“公式太复杂”错误
'在Excel(2010)中的VBA实现
'由微软MVP Excel Group的Jerry Latham提供,2005-2011年
'2011年7月23日
'======================================
双色暗低_a
双色调暗低_b
将f调为双精度
我是双人的
双精度U1
双精度U2
Dim sinU1为双精度
双精度sinU2
Dim cosU1为双精度
Dim cosU2为双精度
暗淡的lambda是双色的
双色暗羔羊
Dim iterLimit为整数
双色暗辛兰达
暗淡的cosLambda为双色
作为双精度的Dim-sinSigma
作为双重标准差
双精度标准差
双倍暗信标
模糊cosSqAlpha为双精度
暗淡的cos2SigmaM为双色
双精度C
双精度uSq
将上部A调暗为双色
将上_B调暗为双色
暗deltaSigma为双
Dim s作为“双精度”最终结果,将返回四舍五入到3位小数(mm)。
由JLatham添加,用于分解“过于复杂”的公式
'分为几部分,以正确计算以下公式
'并在使用时防止溢出错误
'Windows 7 x64系统上的Excel 2010 x64
将P1标注为“双精度”,用于计算复杂公式的一部分
将P2标注为“双精度”,用于计算复杂公式的一部分
将P3标注为“双精度”,用于计算复杂公式的一部分
”“看到了吗https://en.wikipedia.org/wiki/World_Geodetic_System
'以获取有关其他标准的各种椭球体参数的信息。
“low_a和low_b,以米为单位
'==GRS-80===
‘低_a=6378137
‘低_b=6356752.314245
'f=1/298.257223563
'
据报道,英国和北欧的准确率最高。
‘低_a=6377563.396
‘低_b=6356256.910
'f=1/299.3249646
'
’==国际1924年===
‘低_a=6378388
‘低_b=6356911.946
'f=1/297
'
'==克拉克1880型===
‘低_a=6378249.145
‘低_b=6356514.86955
'f=1/293.465
'
'==GRS-67===
‘低_a=6378160
‘低_b=6356774.719
'f=1/298.247167
'==WGS-84椭球体参数===
低_a=6378137'+/-2m
低_b=6356752.3142
f=1/298.257223563
'====================================
L=toRad(lon2-lon1)
U1=Atn((1-f)*Tan(toRad(lat1)))
U2=Atn((1-f)*Tan(toRad(lat2)))
sinU1=Sin(U1)
cosU1=Cos(U1)
sinU2=Sin(U2)
cosU2=Cos(U2)
λ=L
lambdaP=2*PI
如果需要,可将iterLimit=100'设置为低至20。
而(Abs(lambda-lambdaP)>ε)和(iterLimit>0)
iterLimit=iterLimit-1
sinLambda=Sin(lambda)
科斯拉姆达=