VBA TIPS
Get Text and HTML from the Internet Explore

Once an object has been made with using CreateObject Function, we can access/handle to the object. But when I wrote the code for handling other object, I don't know all of what kind of the properties/methods the object has.

In that case [F8] key and the Locals window really helps me.
Placing the mouse cursor on the code line on the procedure then press [F8] key, the executed code line will be highlighted as follows.

When after the code line Set strDoc = ie.Document was executed, please have a look at the Locals window.



Now you can see a variant named strDoc in the Expression area. Clicking the + mark, you can expand the Expression to see the child expressions.
Properties, Values and Type can be seen here.

Please note, this is just one example how to coding, so don't forget that you can also use other handy functions like object browser, watch window ... etc.



The following code get the TEXT or the HTML source from my website and print it in the immediate window.
The immediate window of your VBE will be as follows.




Option Explicit

Sub GetTextFromIe()
    Const strMsg As String = "To get text click [Yes], To get Html click [No]"
    Const sURI As String = "http://www.puremis.net/excel/"
    Dim ie As Object
    Dim strDoc As Object
    Dim bln As Boolean

   Set ie = CreateObject("internetexplorer.application")
    ie.Navigate sURI
    Set strDoc = ie.Document
    If MsgBox(strMsg, vbYesNo) = vbYes Then bln = True

    If bln Then  'As Text
        Debug.Print strDoc.body.innerText
    Else    'As Html
        Debug.Print strDoc.body.innerHTML
    End If

    Set strDoc = Nothing
    Set ie = Nothing
End Sub




| HOME |
Copyright © cellmasters.net - colo's junk room All Right Reserved
ABOUT
WORKS
THE CELL MASTERS
CONTACT
LINKS
Tips and Information about Microsoft Excel|Masaru Kaji aka Colo