Ngabo
Ngabo

Reputation: 31

Internet scraping issue when using vba on secure site

I am trying to automate IE to pull data from a secure site how every I keep getting the same error message: "Object required"

The debugger points to the line -HTMLinput.Value = "test"

Everything before works fine. I don't know what's the problem. I have verified my ID to make sure there is no mistakes.

Sub Brows()

    Dim IE As New SHDocVw.InternetExplorerMedium
    Dim Policy As Object
    Dim certificate As Object
    Dim HTMLDoc As MSHTML.HTMLDocument
    Dim HTMLinput As MSHTML.IHTMLElement

    IE.Visible = True
    IE.navigate "secure website address"
    Application.Wait Now + TimeValue("00:00:02")

    Do While IE.ReadyState <> READYSTATE_COMPLETE
    Loop

    Set HTMLDoc = IE.Document
    Set HTMLinput = HTMLDoc.getElementById("input ID")
    HTMLinput.Value = "test"
End Sub

Upvotes: 1

Views: 64

Answers (1)

ASH
ASH

Reputation: 20362

How to log into a web site using Excel and VBA.

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 = "[email protected]"
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

The program requires references to the following:

1 Microsoft Internet Controls

2. Microsoft HTML Object Library

http://vbadud.blogspot.com/2009/08/how-to-login-to-website-using-vba.html

Upvotes: 1

Related Questions