Log onto Website via VBA


New Member
Oct 9, 2017

I have the below code, it opens the website www.reece.com.au/myaccount/login, but does not fill in the email and password (Correct information on code has been removed for privacy)

I assume it is not working as I have not referenced the correct name in HTML. I assume it is email and password, but I may be wrong. I also am unable to find if MyHTML_Element.Type = "submit" is actually submit. Can anyone please look at the HTML and tell me if I have the wrong information in my VBA?

Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Sub MyReece()

Dim MyHTML_Element As IHTMLElement
Dim MyURL As String

On Error GoTo Err_Clear
MyURL = "https://www.reece.com.au/myaccount/login"

Set MyBrowser = New InternetExplorer

MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.document
HTMLDoc.all.Email.Value = "Infousername"
HTMLDoc.all.password.Value = "Info password"
For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")
If MyHTML_Element.Type = "submit" Then MyHTML_Element.Click: Exit For
If Err <> 0 Then
Resume Next
End If
End Sub

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Kenneth Hobson

Well-known Member
Feb 6, 2007
Welcome to the forum! I hope this is not a hack request.

Normally, I don't see a need for Wait. The loop methods or waiting for a new url works for me. That site is the slowest I have seen.
Sub Test_LoginReece()
    LoginReece "kEmail", "kPassword"
End Sub

' Add references in Tools > References for:
' Microsoft HTML Object Library
' Microsoft Forms 2.0 Object Library
' Microsoft Internet Controls
Sub LoginReece(email As String, password As String)
    Const strURL_c As String = "https://www.reece.com.au/myaccount/login"
    Dim url As String
    Dim objIE As SHDocVw.InternetExplorer
    Dim ieDoc As MSHTML.HTMLDocument
    Dim tbxPwdFld As MSHTML.HTMLInputElement
    Dim tbxUsrFld As MSHTML.HTMLInputElement
    Dim btnSubmit As MSHTML.HTMLInputElement
    Excel.Application.Cursor = xlWait
    On Error GoTo Err_Hnd
    'Create Internet Explorer Object
    Set objIE = New SHDocVw.InternetExplorer
    'Navigate the URL
    objIE.navigate strURL_c
    objIE.Visible = True
    'Wait for page to load
    Do Until objIE.readyState = READYSTATE_COMPLETE: Loop
    'Do: Loop Until objIE.readyState = READYSTATE_COMPLETE
    Set ieDoc = objIE.document
    Application.Wait Now + TimeValue("00:00:05")
    ieDoc.getElementsByName("email").Item(0).Value = email
    ieDoc.getElementById("password").Value = password
    ieDoc.getElementsByClassName("btn btn-primary btn-med ladda-button").Item(0).Click
Err_Hnd: '(Fail gracefully)
    objIE.Visible = True
    On Error GoTo 0
    Excel.Application.Cursor = xlDefault
End Sub


New Member
Oct 9, 2017
Thank you so much Kenneth, works perfectly. I can assure you its not a hack. We are a plumbing company and we price all our jobs using excel, and the above is to allow us to get directly into the supplier pricing website with ease, to ensure all of figures are correct.


New Member
Oct 9, 2017
I may be pushing it but thought I would ask. I also would like to hyperlink various hyperlinks once logged on.

PVC pipe = "https://www.reece.com.au/myaccount/trade/products-and-pricing/product-search/?keyword=pvc+pipe"
PVC Bends = "https://www.reece.com.au/myaccount/trade/products-and-pricing/product-search/?keyword=pvc+bends"

So basically, I can just click on a link in the sheet that says PVC pipe, it will automatically log me on and take me to the relevant page, but also log me on and take me to PVC Bends when I click on that part of the sheet.

For some reason if I just do the hyperlink without the above code (just a straight forward excel hyperlink), the hyperlink will take me the website log on screen, I then put in logon details manually, and then it says something went wrong and it wont log on. This is why I started the whole process of the above in the first place!

Kenneth Hobson

Well-known Member
Feb 6, 2007
I will have to think on that tomorrow.

Likely, what you want to do is to run a macro. It would first check to see if logged in, if not, login. Then it would use the window with the login and navigate to those. Your hypertext would be the one after =. e.g. pvc pipe. The built url would replace " " with "+". Other things could clue the macro in on what you want. You might want a prefix like: Reese - PVC Pipe.

The concept is shown here if you want to try. https://www.extendoffice.com/documents/excel/4422-excel-run-macro-from-hyperlink.html


New Member
Jul 7, 2010
Hi Kenneth,

I was using this to update my VBA because it is needed, but i don't seem to be able to get this to write in the values for email and password automatically.

Can you think of any reason as to why this is??

The field is named "pf.pass" and i can't use the other code suggested for obvious reasons but i can't get this filled out either.

Any suggestion would be gratefully accepted.

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics