

Public Sub parsehtml()ĭim http As Object, html As New HTMLDocument, topics As Object, titleElem As Object, detailsElem As Object, topic As HTMLHtmlElement Loop through each topic, parse each topic’s title, link, upvotes and username using different methods.Get all the latest topics using getElementsB圜lass method.Read more about HTTP requests here – Http requests in Excel VBA First, we pull Hacker News homepage by making a basic HTTP GET request.You can have a look at all the methods using autocomplete but most useful methods are properties are as follows: There are many methods and properties of HTML object and elements. HTML can be set to this object using this syntax : = htmlstring HTML object can be defined using : Dim html As New HTMLDocument Open script editor in excel (alt + f11) and add a reference to Microsoft HTML object library (Tools > references > select)Ī few basics first and then dive into code! Defining and setting HTML.Microsoft HTML object library is used in parsing HTML.Why Hacker News? Because everyone knows Hacker News! Of course, Hacker News has its own API which can be used to pull latest topics but this example is just to learn how to parse HTML. I’m using Hacker News homepage for this example where we parse all the posts from homepage. Few cases are generating multiple HTML files based on excel data, editing multiple HTML files, scraping some data etc. Why parse HTML in Excel VBA? There may be different cases where we need to parse HTML in Excel.
