VBA to connect to a website and click a button not working

MrPink1986

Active Member
Joined
May 1, 2012
Messages
252
Hi,

I have created some code to connect to a website and enter the username and password required to login, once I am logged in I would like to click a button to load a certain page.
This I am having trouble with - I can connect no problem to the site and no issues here.

The code I am using is here;

Code:
Option Explicit

Sub OpenIE(password, username As String)


Dim Clica As Object
Dim Clica2 As Object
Dim IE As InternetExplorerMedium
Set IE = New InternetExplorerMedium
IE.Navigate ("https://products.markit.com/home/login.jsp")
IE.Visible = True
Do While IE.ReadyState <> 4 And IE.Busy
   DoEvents
Loop


IE.Document.getElementById("username").Value = password
IE.Document.getElementById("password").Value = username






For Each Clica In IE.Document.getElementsByTagName("a")
If Clica.className = "button hsprite stylishButton fRight" Then
Clica.click
Set Clica = Nothing
Set IE = Nothing
Exit Sub
End If


Next Clica


Set Clica = Nothing
Set IE = Nothing


End Sub


Sub delay(seconds As Long)
    Dim endTime As Date
    endTime = DateAdd("s", seconds, Now())
    Do While Now() < endTime
        DoEvents
    Loop
End Sub


[COLOR=#ff0000][U][I][B]Sub click_download()[/B][/I][/U][/COLOR]
[COLOR=#ff0000][U][I][B]'Set btnGo = IE.Document.form(0).all("downloadTable") ' method:submit is the button's name[/B][/I][/U][/COLOR]
[COLOR=#ff0000][U][I][B]'btnGo.click[/B][/I][/U][/COLOR]

[COLOR=#ff0000][U][I][B]IE.Document.getElementById("downloadTable").click[/B][/I][/U][/COLOR]
[COLOR=#ffd700]
[/COLOR]
[COLOR=#ffd700]End Sub[/COLOR]


Sub test()


OpenIE "xxx@xxxx.com", "xxxxxx"
Call click_download
End Sub

The red text is my attempt to connect to the button and click.

The button on the site is named "download" and I have attached the code from the site below

}


function downloadTableData(value)
{
theform=document.forms[1];
myurl=******************.href;
var old = theform.action;
var oldmethod=theform.method;
theform.method="POST";
setElemValue(theform,"format",value);
setElemValue(theform,"downloadTable","mainTable");
setElemValue(theform,"querytitle","mainTable");
theform.action = "PresentationServlet";
theform.submit();
theform.action = old;
theform.method=oldmethod;


}






Help greatly appreciated on this.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,215,274
Messages
6,123,993
Members
449,137
Latest member
abdahsankhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top