1

I've been trying to create logins for my work processes. Some websites work.

This link is ALMOST an answer except ieObj is not defined. vba automation in Internet Explorer - clicking different buttons on successive webpages not working?

Here's what I have. Pared down. Italics are variable references. Normally this works great. The button on this website Doesn't have a "name" though. Just a Class, Onclick, and Title (but the title is "" null). I've tried .getelementbytagName(Button), .getelementbyclassname("ButtonThemeA") and a slew of other things. It always errors at the button click section.

How do I reference this button and click it?

I get a Run-Time Error '438'; Object doesn't support this property or method.

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
Community
  • 1
  • 1
PhoenixDirk
  • 23
  • 1
  • 4

1 Answers1

1

If it's the "submit" button, you don't need the name (or ID of that button). What you need is the Form "id". Then you can just say: iedocument.form("formname").submit

I use it in this way:

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
Shimrod
  • 3,115
  • 2
  • 36
  • 56
DataSmarter
  • 197
  • 2
  • 14