VBA Browser Automation

Browser automation can be useful for tasks such as website testing, web automation, and web scraping.

Internet Explorer

Note: Internet Explorer is no longer supported by Microsoft and may not be available.

To automate Internet Explorer use the Microsoft Internet Controls Library and the Microsoft HTML Object Library

Public Sub PrintDOM(URL As String)

    Dim IE      As Object   'SHDocVw.InternetExplorer
    Dim HTMLDoc As Object   'MSHTML.HTMLDocument

    Set IE = CreateObject("InternetExplorer.Application")

    IE.Visible = True
    IE.Navigate URL

    Do Until IE.ReadyState = 4 'READYSTATE_COMPLETE
        DoEvents
    Loop

    Set HTMLDoc = IE.Document

    Debug.Print HTMLDoc.body.innerHTML

    Set HTMLDoc = Nothing

    IE.Visible = False
    IE.Quit

    Set IE = Nothing

End Sub