如何使用VBA单击“提交”按钮

时间:2017-12-01 10:24:28

标签: excel vba

我有一个网页,我想要自动登录并点击提交按钮,使用vba代码如下

'start a new subroutine called SearchBot
Sub SearchBot()

    'dimension (declare or set aside memory for) our variables
    Dim objIE As InternetExplorer 'special object variable representing the IE browser
    Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element
    Dim y As Integer 'integer variable we'll use as a counter
    Dim result As String 'string variable that will hold our result link

    'initiating a new instance of Internet Explorer and asigning it to objIE
    Set objIE = New InternetExplorer

    'make IE browser visible (False would allow IE to run in the background)
    objIE.Visible = True

    'navigate IE to this web page (a pretty neat search engine really)
    objIE.navigate "mywebpage"

    'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

    'in the search box put cell "A2" value, the word "in" and cell "C1" value
    objIE.document.getElementById("loginID").Value = ("userid")
    objIE.document.getElementById("password").Value = ("password")

在此代码之后我想使用vba点击提交按钮

HTML检查元素代码在

下面
<INPUT class=btn2 type=submit value=Submit name=submit1>

1 个答案:

答案 0 :(得分:1)

尝试按名称查找元素并单击它。

objIE.document.getElementsByName("submit1")(0).click