sonjaburke
New Member
- Joined
- Jan 15, 2018
- Messages
- 1
Hello! I am trying to write a macro and the first thing I need to do is log in to a website. It appears that I am able to have the macro open up the website, enter the username and password but I'm struggling with getting it to submit. Can someone tell me what I'm missing here?
Here is the page that I am trying to submit on.
Thank you!
Code:
Dim HTMLDoc As HTMLDocumentDim MyBrowser As InternetExplorer
Sub LogInBNSFSite()
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "https://custidp.bnsf.com/bnsfauth/LoginPage?am-url=https%3A%2F%2Fcustidp.bnsf.com%2Fsps%2Fbnsfcustidp%2Fsaml20%2Flogininitial%3FRequestBinding%3DHTTPPost%26PartnerId%3Dhttps%3A%2F%2Fsp.bnsf.com%2Fsps%2Fbnsfsp%2Fsaml20%26Target=https://customer.bnsf.com/&am-user="
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.readystate = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.document
HTMLDoc.all.UserId.Value = "sburke" 'Enter username
HTMLDoc.all.Password.Value = "Kalama02" 'Enter password
For Each HTML_Element In HTMLDoc.getElementsByTagName("input")
If MyHTML_Element.Type = "submit" Then MyHTML_Element.Click: Exit For
Next
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
Here is the page that I am trying to submit on.
Thank you!