【问题标题】:VBA Macro to interact with specific website与特定网站交互的 VBA 宏
【发布时间】:2016-06-09 18:07:02
【问题描述】:

我正试图让我的宏让我登录到一个网站。到目前为止,我已经输入了我的用户名和密码,但我不知道如何让它“点击”按钮。该网站是https://www.aum-inc.com/log-in,登录按钮不是我知道如何激活的那种。它有某种javascript。下面是我的代码,其中 HELP 由我需要针对这种特定情况更新的两行编写。

Sub AUM()
 'we define the essential variables
Dim ie As Object
Dim pwd, username
Dim button

'add the "Microsoft Internet Controls" reference in your VBA Project indirectly
Set ie = CreateObject("InternetExplorer.Application")
With ie
    .Visible = True
    .Navigate ("https://www.aum-inc.com/log-in")
    While ie.ReadyState <> 4
        DoEvents
    Wend
    Set username = .document.getElementById("cphContent_C001_txtUserName") 'id of the username control (HTML Control)
    Set pwd = .document.getElementById("cphContent_C001_txtPassword") 'id of the password control (HTML Control)
    'HELP Set button = .document.getElementById("ctl00$cphContent$C001$btnPropLogon") 'id of the button control (HTML Control)
    username.Value = "Account1234"
    pwd.Value = "Password1234"
    'HELP button.Click
    While ie.ReadyState <> 4
        DoEvents
    Wend
End With

'insert some sort of code in VBA to find account

Set ie = Nothing

结束子

【问题讨论】:

  • 试试,ie.document.getElementsbyName("btnsubmit")(0).click.

标签: javascript excel vba macros


【解决方案1】:

那个 URL 对我不起作用,但实际上你就是这样做的。

Dim HTMLDoc As HTMLDocument
Dim oBrowser As InternetExplorer
Sub Login_2_Website()

Dim oHTML_Element As IHTMLElement
Dim sURL As String

On Error GoTo Err_Clear
sURL = "https://www.google.com/accounts/Login"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True

Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE

Set HTMLDoc = oBrowser.Document

HTMLDoc.all.Email.Value = "sample@vbadud.com"
HTMLDoc.all.passwd.Value = "*****"

For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
Next

' oBrowser.Refresh ' Refresh If Needed
Err_Clear:
If Err <> 0 Then
Debug.Assert Err = 0
Err.Clear
Resume Next
End If
End Sub
  1. Microsoft Internet 控件

  2. Microsoft HTML 对象库

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-10
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 2012-11-08
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多