Want to read the text within the body of a web site without a WebBrowser control RRS feed

  • Question

  • I have a need to call a web site and get the response back into a variable (I prefer not to have to have a WebBrowser control on my form)

    I am using Access 2013.  I would like to not have to use a Web Browser Control (as I currently am using)

    Currently I am using:

        vBrowserCommandString = "" & Me.TextBoxUserName & "&Password=" & Me.TextBoxPassword
        Me.WebBrowser0.ControlSource = vBrowserCommandString

    Me.TextBoxWebReturn = Me.WebBrowser0.Object.Document

    The last line does not display the text in the body of the web site but displays the text "[object HTMLDocument]"

    I need the text that is contained within the body of the web page.  

    Monday, October 31, 2016 2:27 PM

All replies

  • Why not use MSXML?  Something like:

    'sURL -> URL to extract, do not forget the http://www. part
    Function GetSiteHTML(sURL As String) As String
        On Error GoTo Error_Handler
        Dim oMSXML                As Object    'SHDocVw.InternetExplorer
        Set oMSXML = CreateObject("MSXML2.XMLHTTP")
        With oMSXML
            .Open "GET", sURL, False
        End With
        GetSiteHTML = oMSXML.responseText
        On Error Resume Next
        If Not oMSXML Is Nothing Then Set oMSXML = Nothing
        Exit Function
        MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
               "Error Number: " & Err.Number & vbCrLf & _
               "Error Source: GetSiteHTML" & vbCrLf & _
               "Error Description: " & Err.Description & _
               Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
               , vbOKOnly + vbCritical, "An Error has Occured!"
        Resume Error_Handler_Exit
    End Function

    Then you could simply call it like:

    sHTML = GetSiteHTML("" & Me.TextBoxUserName & "&Password=" & Me.TextBoxPassword)

    Daniel Pineault, 2010-2016
    Microsoft MVP Professional Support:
    MS Access Tips and Code Samples:

    Monday, October 31, 2016 2:40 PM
  • Thanks worked great.  Will taking more than 5 minutes to load?  there be any problems if the site takes minutes to load?  Also how can I test for some too long time like if it takes more than 3 minutes to respond. What if it takes an entire minute but less than my too long time to quit time?

    for others that may want to use this the line GetSite = oMSXML.responseText

    should be GetSiteHTML = oMSXML.responseText

    Monday, October 31, 2016 5:16 PM
  • Hi 3JS1976,

    Thanks for your sharing. I assume that a long time load is related with this web site, If you make a test with Google, will it waste long?

    For your original issue about reading test from web site, I would suggest you mark the suggestion from Daniel as answer.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Saturday, November 5, 2016 5:52 AM