2017-09-21 140 views
0

我想從網站拉動信息,但不能爲我的生活弄清楚如何點擊按鈕。我已經有了輸入信息的代碼。這是該網站的HTML。任何幫助,將不勝感激。使用VBA點擊一個按鈕

<p role="button" tabindex="0" class="fmtbutton" onkeypress="finddistancebetweenaandb(document.forms['inp']['pointa'].value,document.forms['inp']['pointb'].value);" onclick="finddistancebetweenaandb(document.forms['inp']['pointa'].value,document.forms['inp']['pointb'].value);">&nbsp;Show&nbsp;</p> 

以下是我到目前爲止的完整代碼。

Sub RoundedRectangle1_Click() 
Dim eRow As Long 
Dim ele As Object 
Dim objIE As Object 

Set objIE = CreateObject("InternetExplorer.Application") 
FranchiseAddress = Range("B2").Value 
Movefrom = Range("B3").Value 
moveto = Range("B4").Value 

With objIE 
    .Visible = True 
    .navigate "https://www.freemaptools.com/how-far-is-it-between.htm" 
Do While .Busy Or _ 
.readyState <> 4 
DoEvents 
Loop 
Set d = .Document.getElementsByName("onoffswitch") 
d.Item(0).Click 
Set f = .Document.getElementsByName("pointa") 
f.Item(0).Value = FranchiseAddress 
Set a = .Document.getElementsByName("pointb") 
a.Item(0).Value = Movefrom 

「這是我堅持」

End With 
End Sub 

我曾嘗試在此網站上發現了很多問題,多種解決方案,但他們都不工作。

謝謝。

+0

這已被要求,並回答了這麼多次添加到您的代碼。請做研究。然後回來,如果你有代碼,你需要幫助。 – jsotola

+0

我已經嘗試了很多次,從本網站有多個答案。我將用我到目前爲止的代碼進行編輯。 –

+0

那會很好 – jsotola

回答

0

Dim aaa As Object 
Set aaa = .Document.getElementsByClassName("fmtbutton") ' this returns 4 objects, your button is the first one 
aaa(0).Click 
+0

'aaa(1).Click'切換全屏 – jsotola