1

我一直在尝试为我的工作流程创建登录名。一些网站工作。

这个链接几乎是一个答案,除了 ieObj 没有定义。Internet Explorer 中的 vba 自动化 - 单击连续网页上的不同按钮不起作用?

这就是我所拥有的。削减了。斜体是变量引用。通常这很好用。该网站上的按钮虽然没有“名称”。只是一个类、Onclick 和标题(但标题为“”空)。我尝试过 .getelementbytagName(Button)、.getelementbyclassname("ButtonThemeA") 和许多其他东西。它总是在按钮单击部分出错。

如何引用此按钮并单击它?

我收到运行时错误“438”;对象不支持此属性或方法。

Sub Login1()

    Dim ieApp As InternetExplorer
    Dim ieDoc As Object
    Dim LoginVal As String
    Dim PassVal As String
    Dim ieForm As Object
    Dim ieObj As Object


    'create a new instance of ie
    Set ieApp = New InternetExplorer

    'you don’t need this, but it’s good for debugging
    ieApp.Visible = True

    'Login Screen
    ieApp.Navigate "*webpage to login*"
    Do While ieApp.Busy: DoEvents: Loop
    Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

    'Get the login values
    LoginVal = Workbooks("Macrobook").Sheets("Login").Cells(2, 3).Value
    PassVal = Workbooks("Macrobook").Sheets("Login").Cells(2, 4).Value
    Set ieDoc = ieApp.Document

    'fill in the login form
    With ieDoc
        .getElementById("usr_name").Value = LoginVal
        .getElementById("usr_password").Value = PassVal
        .getElementbyTagName(button).Click
    End With
    Do While ieApp.Busy: DoEvents: Loop
    Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

    'To acct list screen
    ieApp.Navigate "*Acct list URL - Not important for this question*"
    Do While ieApp.Busy: DoEvents: Loop
    Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

    'And it goes on from here.

End Sub
4

1 回答 1

1

如果是“提交”按钮,则不需要名称(或该按钮的 ID)。您需要的是表格“id”。然后你可以说:iedocument.form("formname").submit

我以这种方式使用它:

Sub website_newtitle()

    target_form = "model-node-form" '<-- THE FORM ID      
    target_url = ThisWorkbook.Sheets("models").Cells(1, 1).Value
    new_title = ThisWorkbook.Sheets("models").Cells(1, 2).Value

    'Modification
    Dim ie As New InternetExplorer
    Dim LookUpValue As String
    Dim HtmlDoc As HTMLDocument
    Dim SubmitInput As HTMLInputElement

    ie.Navigate target_url
    Do Until ie.ReadyState = READYSTATE_COMPLETE 'wait till the page is loaded
    Loop

    Set HtmlDoc = ie.document

    With ie
        .Visible = True 'disable to remain invisible
        .AddressBar = True
        .Toolbar = True
    End With

    HtmlDoc.forms(target_form).elements("edit-title").Value = new_title

    'submit data
    HtmlDoc.Forms(target_form).Submit '<-- SUBMIT THE FORM
    Do Until ie.ReadyState = READYSTATE_COMPLETE 'wait till the page is loaded

     'close window
     ie.Quit
End Sub
于 2013-08-02T17:58:16.020 回答