woodworkingpa
New Member
- Joined
- Oct 16, 2018
- Messages
- 1
Hello friends,
After several searches on google, it looks that MrExcel is the best place to get VBA Excel help.
I am trying to login to different websites automatically. The goal is create a function that will handle all repetitive tasks inside the sub routine, so the code for each different website login will be shorter.
First here is the code that is currently working for one test website "FaceBook":
Sub OpenFacebook()Dim ie As Object
I tried to create a function/private sub called "OpenLink" that could handle the repetitive tasks as shown below, but it is not working:
Private Sub OpenLink(ByVal url As String, ByVal isVisible As Boolean)
And then I am including "OpenLink" in the sub routine:
Sub OpenFacebookTest()
When I step through it, it does not show me any errors, but it does not automatically enters the user name and password in the fields and the submit button is not clicked.
Any help you can provide will be greatly appreciate it.
Thank you
Toni Ln.
After several searches on google, it looks that MrExcel is the best place to get VBA Excel help.
I am trying to login to different websites automatically. The goal is create a function that will handle all repetitive tasks inside the sub routine, so the code for each different website login will be shorter.
First here is the code that is currently working for one test website "FaceBook":
Sub OpenFacebook()Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.navigate Sheets("Sheet1").Cells(2, 5) ' Sheet1, Row 2, column 5 has the Link to FaceBook
ie.Visible = True
Do While ie.Busy And Not ie.readyState = 4
DoEvents
Loop
DoEvents
On Error Resume Next
ie.document.all.Item("email").Value = Sheets("Sheet1").Range("B2") ' Cell "B2" in Sheet1 has the user name
ie.document.all.Item("pass").Value = Sheets("Sheet1").Range("C2") ' Cell "C2" in Sheet1 has the password
ie.document.all.Item("loginbutton").Click
End Subie.navigate Sheets("Sheet1").Cells(2, 5) ' Sheet1, Row 2, column 5 has the Link to FaceBook
ie.Visible = True
Do While ie.Busy And Not ie.readyState = 4
DoEvents
Loop
DoEvents
On Error Resume Next
ie.document.all.Item("email").Value = Sheets("Sheet1").Range("B2") ' Cell "B2" in Sheet1 has the user name
ie.document.all.Item("pass").Value = Sheets("Sheet1").Range("C2") ' Cell "C2" in Sheet1 has the password
ie.document.all.Item("loginbutton").Click
I tried to create a function/private sub called "OpenLink" that could handle the repetitive tasks as shown below, but it is not working:
Private Sub OpenLink(ByVal url As String, ByVal isVisible As Boolean)
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.navigate url
ie.Visible = isVisible
Do While ie.Busy And Not ie.readyState = 4
DoEvents
Loop
DoEvents
End SubSet ie = CreateObject("InternetExplorer.Application")
ie.navigate url
ie.Visible = isVisible
Do While ie.Busy And Not ie.readyState = 4
DoEvents
Loop
DoEvents
And then I am including "OpenLink" in the sub routine:
Sub OpenFacebookTest()
OpenLink Sheets("Sheet1").Cells(2, 5), True
On Error Resume Next
ie.document.all.Item("email").Value = Sheets("Sheet1").Range("B2")
ie.document.all.Item("pass").Value = Sheets("Sheet1").Range("C2")
ie.document.all.Item("loginbutton").Click
End SubOn Error Resume Next
ie.document.all.Item("email").Value = Sheets("Sheet1").Range("B2")
ie.document.all.Item("pass").Value = Sheets("Sheet1").Range("C2")
ie.document.all.Item("loginbutton").Click
When I step through it, it does not show me any errors, but it does not automatically enters the user name and password in the fields and the submit button is not clicked.
Any help you can provide will be greatly appreciate it.
Thank you
Toni Ln.