大家下午好
我正在开展一个工作项目,我需要根据注册号和里程获取车辆值,并将这些值输入 Excel 电子表格。
注册号和里程存储在电子表格中,但我不知道从哪里开始。
我上周末创建了一个粗略的 VBA 应用程序,如下所示
注册号和里程存储在电子表格中,但我不知道从哪里开始。
上周末我创建了一个粗略的 VBA 应用程序,如下所示:
子 GetHTMLDocument()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim Email As MSHTML.IHTMLElement
Dim Password As MSHTML.IHTMLElement
Dim LoginButton As MSHTML.IHTMLElement
Dim REG As MSHTML.IHTMLElement
Dim Mileage As MSHTML.IHTMLElement
Dim CAPGo As MSHTML.IHTMLElement
Dim objEvent
Dim GetValue As MSHTML.IHTMLElement
'Show IE for testing purposes
IE.Visible = True
'Navigate to web page
IE.Navigate "https://valuationanywhere.cap.co.uk/LoginPage?ReturnUrl=%2f%3f__hstc%3d208265677.8bb2d3e6c872f15cd37070c17648ee29.1549763639794.1549763639794.1549763639794.1%26__hssc%3d208265677.1.1549763639794%26__hsfp%3d959865525&__hstc=208265677.8bb2d3e6c872f15cd37070c17648ee29.1549763639794.1549763639794.1549763639794.1&__hssc=208265677.1.1549763639794&__hsfp=959865525"
'Loop an empty loop until done
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = IE.Document
'inputs email address
Set Email = HTMLDoc.getElementById("inputLoginEmail")
Email.Value = "email"
'inputs password
Set Password = HTMLDoc.getElementById("inputLoginPassword")
Password.Value = "password"
'Clicks login button
Set LoginButton = HTMLDoc.getElementById("btnLogin")
LoginButton.Click
'Wait 3 seconds for page to load
Application.Wait (Now + TimeValue("0:00:03"))
Set objEvent = IE.Document.createEvent("HTMLEvents")
'Input REG into text box
Set REG = HTMLDoc.getElementById("vrm")
REG.Value = "reg"
'Input mileage into text box
Set Mileage = HTMLDoc.getElementById("mileage")
Mileage.Value = "181000"
'Fakes data entry as no focus is given to the text box
objEvent.initEvent "change", False, True
REG.dispatchEvent objEvent
Mileage.dispatchEvent objEvent
'Clicks Go button
Set tags = IE.Document.getElementsByTagName("button")
For Each tagx In tags
If tagx.innerText = "Go" Then
tagx.Click
Exit For
End If
Next
'Wait 3 seconds for popup to load
Application.Wait (Now + TimeValue("0:00:03"))
Set tags = IE.Document.getElementsByTagName("button")
For Each tagx In tags
If tagx.innerText = "Create NEW Valuation" Then
tagx.Click
Exit For
End If
Next
这将导航到页面,让我登录并搜索估值。然而,我们最终将拥有一个包含数百辆汽车的数据库,我们希望获得估值,我们的 CAP 服务在这里有一些插件 - https://soap.cap.co.uk/vrm/capvrm.asmx?op=VRMValuation
有什么办法可以让 VBA 从一张表中选择一个 reg 和里程,然后拉回价值?
我不指望有人会写出我想从中学习的全部内容。但是谁能指出我正确的方向?
最诚挚的问候, 克雷格