Getting VBA excel 2007 to recognize a button on a website
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.
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]
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