Excel Macro To Automate Log-In Credentials

rameezl17

Board Regular
Joined
Mar 6, 2018
Messages
105
Hi Everyone,

I am trying to automate logging into a company website, so I can just click a button (I created a shape and assigned the macro below to the shape) and it does it for me.

I am using the below code and it brings me to the desired website but it will not enter my credentials. I do not get an error code or anything, it just doesn't populate the log in credentials. I have looked up the source element for username/password/sign on and I think the naming I put in the code is correct. I also used the correct references as well when I go to Tools > References> "Microsoft HTML Object Library and Microsoft Internet Controls".

Again since this is a company specific website I'm not sure if you will be able to see it so I did not include in the thread. If you can provide an example of another website and the code that works to log in or help with this one that would be greatly appreciated. Thank you very much for the help!

Dim HTMLDoc As HTMLDocument
Dim oBrowser As InternetExplorer
Sub Login_2_Website()
Dim oHTML_Element As IHTMLElement
Dim sURL As String
On Error GoTo Err_Clear
sURL = "samplewebsite.com"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True
Do
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.Document
HTMLDoc.all.UserName.Value = "abc123"
HTMLDoc.all.Password.Value = "abc123!"
For Each oHTML_Element In HTMLDoc.getElementsByTagName("Sign On")
Debug.Print oHTML_Element.Name
Next
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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