-3

I just want to know the following:

  1. How do I login to a pages using VBA?
  2. How do I click on various options in a web page using VBA?
  3. How do I enter text into required forms in a web page using a VBA?
Zev Spitz
  • 13,950
  • 6
  • 64
  • 136
  • 1
    Welcome to stack overflow :-) please look at how to [ask]. This site isn't a code generator. – JimHawkins Nov 02 '16 at 06:44
  • You can just [search StackOverflow properly](http://stackoverflow.com/a/7413486/111794). In particular, search for the [vba] and [mshtml] tags (http://stackoverflow.com/questions/tagged/mshtml%20vba?mode=all). – Zev Spitz Nov 02 '16 at 07:32
  • Possible duplicate of [Reading Web Pages using Excel VBA](http://stackoverflow.com/questions/7393236/reading-web-pages-using-excel-vba) – Zev Spitz Nov 02 '16 at 07:32

1 Answers1

0

Here is a classic example of how to do all of those things.

Dim HTMLDoc As HTMLDocument
Dim oBrowser As InternetExplorer
Sub Login_2_Website()

Dim oHTML_Element As IHTMLElement
Dim sURL As String

On Error GoTo Err_Clear
sURL = "https://www.google.com/accounts/Login"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True

Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE

Set HTMLDoc = oBrowser.Document

HTMLDoc.all.Email.Value = "sample@vbadud.com"
HTMLDoc.all.passwd.Value = "*****"

For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
Next

' oBrowser.Refresh ' Refresh If Needed
Err_Clear:
If Err <> 0 Then
Debug.Assert Err = 0
Err.Clear
Resume Next
End If
End Sub

Make sure to set references to: Microsoft HTML Object library & Microsoft Internet Controls