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
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