Getting VBA excel 2007 to recognize a button on a website

vba automation in Internet Explorer - clicking different buttons on successive webpages not working?

The link above is an ALMOST answer to what I am looking for except ieObj is not defined. I'm relatively new VBA programming so I'm not sure how to fix this information.

I've been trying to create logins for my work processes. Some websites work just fine. Some of it sucks (javascript and I can't pick out what I need).

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 make VBA reference this button and click it?

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

Also a side question. Is there a place where I can find a sort of flow chart for available applications, objects, methods, and properties with description? I have a VBA macro that runs InternetExplorer.documents.forms(0). I can't find any information on why that'd work, but it does. No friggin clue why.

Thanks in advance for all your help.

[code] 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 [/code]

Answers


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

Need Your Help

Get input value from parent document

php variables curl

I'm using CURL to scrape a website like this:

WordPress Login in jQuery Popup - How to validate login with jQuery Ajax?

jquery wordpress login

I have the WordPress Login form working in the front-end of my website, to allow my users to login without having to visit the wp-login.php or leave the "theme" or the website.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.