Macro To Automatically Log Onto Website

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 on an excel spreadsheet (I created a shape and assigned the macro below to the shape) and it logs on for me.

I am using the code below 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 for the website 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 it in the thread. If someone can please 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
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Watch MrExcel Video

Forum statistics

Threads
1,123,380
Messages
5,601,288
Members
414,440
Latest member
Kim0204

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
Top