Log into Facebook account and post

jaryszek

Board Regular
Joined
Jul 1, 2016
Messages
213
Hi Guys,

I was looking trough internet and forums but i have not found anything helpful so I am writing here.

I have code and this is working for me to log on Facebook:

Code:
Sub Login_facebook()     
    Dim ie As Object
     
     Dim aelement
     Dim btnInput
     Dim btnInputer
     
    Set ie = CreateObject("InternetExplorer.Application")
     
    ie.navigate "http://www.facebook.com/login.php"
     
    ie.Visible = True
     
    Do While ie.Busy And Not ie.readyState = 4
        DoEvents
    Loop
     
    DoEvents
     
    ie.document.All.Item("email").Value = "xxx@com.pl"
    ie.document.All.Item("pass").Value = "yyyyy"
    ie.document.All.Item("login").Click
     Application.Wait (Now + TimeValue("00:00:02"))
    ie.navigate "https://www.facebook.com/groups/496722467127307/"
    Do While ie.Busy And Not ie.readyState = 4
        DoEvents
    Loop

I would like to additionally post.
But i don't know how to find a specific class and find a button "send".

The class for writing text in posting windows is "_1mf _1mj" but
ie.document.all.getbyclassname("_1mf _1mj") doesn't work for me.

Przechwytywanie.jpg



Please help
Jacek Antek
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
should it not be:

IE.document.getElementsByClassName("_1mf _1mj")
 
Upvote 0
Can you create a dummy login account and share the login details so that I can help with you something.
 
Upvote 0
Try this:

Set reference to Microsoft Internet Controls and Microsoft HTML object library before executing this code.

Code:
Dim ie As InternetExplorer
Sub Ombir_03Dec2016()
Dim doc As HTMLDocument
Dim msg As String

Set ie = New InternetExplorer
msg = "Testing Finished"

With ie
    .Visible = True
    .Navigate "m.facebook.com"
    Call IEReady
End With

Set doc = ie.Document

doc.getElementById("email").Value = "jaryszek@o2.pl"
doc.getElementById("pass").Value = "Testtest1234"
doc.getElementById("login").Click
    Call IEReady
doc.getElementsByName("xc_message")(0).Value = msg
doc.getElementsByName("view_post")(0).Click
    Call IEReady
    ie.Quit
End Sub
Sub IEReady()
Do While ie.Busy: DoEvents: Loop
waitfor 1
    Do While ie.ReadyState <> 4
        waitfor 3
    Loop
End Sub
Sub waitfor(ByVal nSec As Long)
nSec = nSec + Timer
    Do While Timer < nSec
       DoEvents
    Loop
End Sub
 
Upvote 0
Hi Ombir,

it is very clever way of doing this. Thank You very much for your help, this is working.

Could you please explain why did you do this via facebook mobile page?
It is simpler to get to specific class?

and what means "(0)" in this code? :

Code:
doc.getElementsByName("xc_message")(0).Value = msg

Please explain this I am very curious!

Jacek
 
Last edited:
Upvote 0
Mobile version is less complicated as compare to web version. That's why I choose it.

doc.getElementsByName("xc_message") always returns collection of items. 0 means first item in that collection, 1 means second and so on.

You can also try this web version:

Code:
Dim ie          As InternetExplorer
Sub Ombir_03Dec2016()
Dim doc         As HTMLDocument
Dim msg         As String
Dim Statusbox   As Object

Set ie = New InternetExplorer
msg = "Web Testing"

With ie
    .Visible = True
    .Navigate "www.facebook.com"
    Call IEReady
End With

Set doc = ie.Document

doc.getElementById("email").Value = "jaryszek@o2.pl"
doc.getElementById("pass").Value = "Testtest1234"
doc.getElementById("u_0_n").Click
    Call IEReady
Do While Statusbox Is Nothing
    On Error Resume Next
    Set Statusbox = doc.getElementsByName("xhpc_message")(0)
Loop
On Error GoTo 0
Statusbox.Value = msg
doc.getElementsByClassName("_42ft _4jy0 _ej1 _4jy3 _4jy1 selected _51sy")(0).Click
    Call IEReady
    ie.Quit
End Sub
Sub IEReady()
Do While ie.Busy: DoEvents: Loop
waitfor 1
    Do While ie.ReadyState <> 4
        waitfor 3
    Loop
End Sub
Sub waitfor(ByVal nSec As Long)
nSec = nSec + Timer
    Do While Timer < nSec
       DoEvents
    Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,322
Messages
6,124,241
Members
449,149
Latest member
mwdbActuary

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