Hi guys,

I'm aware of the fact that there are multiple threads on this subject already, and that there are loads of information but somehow I can't get my VBA code to work. I'm trying to fetch data from a password protected website using VBA. I can login, but somehow I keep getting the log in page HTML into my Excel. Of course I want to load the page after the login, so I can get the password protected data. I can't provide you with a link to the website, since it's only accesible from the company's network server.

Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
 Sub Stats()

 On Error GoTo Err_Clear
 MyURL = ""
 Set MyBrowser = New InternetExplorer
 MyBrowser.Silent = True
 MyBrowser.navigate MyURL
 MyBrowser.Visible = False
 Do
 Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
 Set HTMLDoc = MyBrowser.document
 HTMLDoc.all.UserName.Value = ""
 HTMLDoc.all.Password.Value = ""
 HTMLDoc.all.RememberMe.Value = "false"
 For Each MyHTML_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
 
 MyBrowser.navigate MyURL
Set HTMLDoc = MyBrowser.document
Range("S2!A1").Value = HTMLDoc.body.innerText
MyBrowser.Quit

 End Sub
I don't get why it keeps showing the log in page data, since I already logged in to the website in the beginning of the macro.

Thanks in advance! I appreciate your help