Get Input Elements Name & Type from HTML Form

I came across one more procedure which gets the names of all the inputs on an html page and also the type of inputs and prints on the debug screen. This will help me to get work done by vba rather than someone sitting and doing the same repetitive tasks for hours and days. I would like to thank Dwildman(Senior Member) at (http://www.ozgrid.com/forum/showthread.php?t=74589) — Selva V Pasupathy

Option Explicit

Sub GetHTMLControls()
'This procedure requires MICROSOFT INTERNET CONTROLS AS A REFERENCE 
    Dim objIEAs InternetExplorer
    Dim htmlDoc AsMSHTML.IHTMLDocument
    Dim htmlColl AsMSHTML.IHTMLElementCollection
    Dim htmlInput AsMSHTML.IHTMLInputElement

    Set objIE = CreateObject("InternetExplorer.Application")

    With objIE
        .Visible = True
        .navigate "https://www.wordpress.com/login/"

        Do While .Busy: DoEvents:  Loop
            Do While .readyState  4: DoEvents: Loop 

                Set htmlColl = .document.getElementsByTagName("INPUT") 

                 ' Check whether I have the right document
                Debug.Print "Doc  name = " & .document.Title

                 ' ***THIS LOOP IS NOT FIRING AT ALL***
                For Each htmlInput In htmlColl
                     Debug.Print "Input element = " & htmlInput.Name & " & Element type = " & _
                                    htmlInput.Type
                Next htmlInput
    End With
End Sub 

Leave a Comment

You must be logged in to post a comment.