Parse html file using MSHTML in VBScript

Eugene picture Eugene · Mar 29, 2012 · Viewed 7.2k times · Source

I'd like to load a string as an html file using MSHTML in VBScript and parse it. I can do this with "InternetExplorer.application" but I'd like to do it with "htmlfile" (MSHTML.HTMLDocument)

The following code:

Set h =  CreateObject("htmlfile")
h.body.innerHTML = "html goes here"

gives this error:

Microsoft VBScript runtime error: Object required: 'body'

How do I load the html string?

Answer

Ekkehard.Horner picture Ekkehard.Horner · Mar 29, 2012

Probably cheating, but seems to work:

  Dim oHF : Set oHF = CreateObject("HTMLFILE")
  oHF.write "<html><body></body></html>"
  oHF.body.innerHTML = "<p>WhatEver</p>"
  WScript.Echo oHF.body.innerTEXT