Website login using HTTPRequest in excel VBA

  • Hi,
    I got a function from

    Function PageAuthorized(ByVal strUrl As String, ByVal strUserId As String, ByVal strPwd As String) As Boolean
    Dim strHtml As String
    Dim objPat As Object
    Dim lngLoop As Long
    Const strPSoftLoginPageUrl As String = ""
    Const strPattern As String = "You are not authorized for this page."
    With CreateObject("MSXML2.XMLHTTP")
    .Open "post", strPSoftLoginPageUrl, False
    .SetRequestHeader "Content - type", "application / x - www - form - urlencoded"
    .Send "userid=" & strUserId & "pwd=" & strPwd
    .Open "get", strUrl, False
    .SetRequestHeader "Content - type", "application / x - www - form - urlencoded"
    strHtml = .responseText
    End With
    With CreateObject("VBScript.Regexp")
    .Global = True
    .ignoreCase = True
    .Pattern = strPattern
    Set objPat = .Execute(strHtml)
    End With
    PageAuthorized = (objPat.Count > 0)
    End Function

    My Global Target is:

    1. Log in to a site ( for example facebook) using HTTP request)
    2. if already log in then search a phone number in facebook, if found then copy profile link back to excel.

    My question is : How the right way to use the above function (PageAuthorized) so I can log in to facebook(using user id and password)? For those who have facebook account please try it and let me know if you get any success..

    I am focusing in step 1 on my global target but if anybody want to give me more idea about step 2 it would be greatly appreciated.


  • administrators

    Hi @bennyys, You cannot login to Facebook or Gmail with a simple GET request. Gmail and FB use OAuth2 authentication method.

    OAuth2 can be implemented in VBA but with some restrictions. VBA-Web can be used for OAuth2. Read more about OAuth2 here -

    The best method for your case is to simply use selenium to mimic the login in the browser and scrape data. More details here -

  • Hi ranjithkumar10,
    Thank you for the link.

  • Hi @ranjithkumar10,
    Apart from I can't use simple GET to log in to FB, could you please check Function PageAuthorized above if you can manage to get it works.


Log in to reply

Looks like your connection to Codingislove Forum was lost, please wait while we try to reconnect.