Search code examples
htmlvbscriptactivexruntime-errormshtml

Parse html file using MSHTML in VBScript


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?


Solution

  • 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