Login into website(FB for my case) using MSXML2.XMLHTTP with VBA

bennyys

New Member
Joined
Jun 22, 2017
Messages
17
Hi,
Let me explain what is my goal and what are my problem on using excel VBA.


My Target:
From my phone record(call log record using super back up) I got list of mobile number.
What I am trying to do now is I will use all these number as input on facebook search.
If those number link with certain profile on FB (in other word FB searching result is not empty) then copy the profile link and paste to excel.
So at the and I will get someting like: phone number in column a and profile link in column B(if any).


My working step:
In the process of find the way to reach my goal, following is my working step
1.Provide excel macro for checking if the internet connection is available. If there is an internet connection then move to the next step, if no internet connection then stop the process.
2.macro for log in to facebook. on this part I classify the step in to 2 parts:
2.1 Log in using internet explorer object
or
2.2 log in using xmlhttp object.
3. if log in is success then the next step is macro for searching phone number in FB and if found something then copy the link address and paste it to excel.If nothing found then jump to the next phone number.Repeat step 3 until the last number on the list.
4. if all done then using excel macro to log out from FB


My Progress so far:
step 1. done
step 2.1 I got several macro and working fine during the test. here is the code


alternative 1
Code:
Sub WebLogin()
Dim a As String
    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        .Visible = True
        .navigate "https://m.facebook.com/login/?ref=dbl&fl&refid=8"
        Do Until .readyState = 4
            DoEvents
        Loop
        .document.all.Email.Value = "[B][I]enter your full email address here[/I][/B]"
        .document.all.pass.Value = "[B]enter your password here[/B]"
        .document.forms(0).submit
    End With
End Sub


alternative 2
Code:
Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Sub MyFB()
 
Dim MyHTML_Element As IHTMLElement
Dim myurl As String
On Error GoTo Err_Clear
myurl = "https://m.facebook.com/login/?ref=dbl&fl&refid=8"
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.Email.Value = "[B]email address[/B]" 'Enter your email id here
HTMLDoc.all.pass.Value = "[B]password"[/B] 'Enter your password here
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
End Sub


alternative 3
Code:
Sub vbax_55399_facebook_login()
    
    With CreateObject("InternetExplorer.Application")
        .Visible = True
        .navigate "http://www.facebook.com/login.php"
        Do While .Busy And Not .readyState = 4
            DoEvents
        Loop
        .document.all.Item("email").Value = "[B]email address[/B]"
        .document.all.Item("pass").Value = "[B]password[/B]"
        .document.all.Item("loginbutton").Click
    End With
End Sub


Step 2.2 No luck yet on this part yet, I am still searching the simple way to do this that is why I need help on this forum.
I got a function during my search but try it with no luck. below is the function
Code:
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 = "http://gmail.com”"' I will change this part to facebook link and adjust the HTML tag accordingly
    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”
        .send
        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


step 3. Searching on FB using data from excel. I haven,t got any luck on this part.
step 4. Haven't reach up to this part but for log out using ie object I can modify the log in macro. for log out using xmlhttp I need help for this part.


Resume of my problem:
I need help from this forum to solve my problem on step:
2.2 log in using xmlhttp object(How to log in to web site in general and to FB in particular using xmlhttp object)
3. How do I use excel macro to search phone number on FB and if found profile then copy the link and paste it to excel.
4. How do I use excel to log out from web site(which is log in previously) especially using xmlhttp object.


Thank you in advance..


Regards,
Benny
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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