0

Can HTMLDocument be forced to a specific documentMode when using MSHTML in Excel?

So far, all properties and methods related to this seem to only return values and cannot be set (ex. documentMode, compatMode, compatible).

While scraping and parsing HTML, I'm getting different behaviours in Excel on other machines in the organization which is why I want to standardize as much as I can.

Code:

Dim doc As HTMLDocument
Set doc = New HTMLDocument

Debug.Print "compatMode: " & doc.compatMode
Debug.Print "documentMode: " & doc.documentMode

My machine:

compatMode: BackCompat
documentMode: 11

Other machines:

compatMode: BackCompat
documentMode: 5

For the systems I compared with, the OS builds and MS Office (O365) versions were the same as my machine. I also compared the version of msxml3.dll and msxml6.dll which were also the same with my machine.

TechFanDan
  • 3,329
  • 6
  • 46
  • 89
  • 1
    https://stackoverflow.com/questions/49501406/vba-doesnt-read-xmlhttp-requests-response-according-to-its-tree-structure change emulation mode ? – QHarr Oct 23 '20 at 16:09
  • thanks! I don't have an entry for Excel. I can't add one either - work computer. – TechFanDan Oct 23 '20 at 16:44

1 Answers1

0
  1. Instead of MSXML2.XMLHTTP.6.0, I used an instance of InternetExplorer
  2. Instead of instantiating various classes from MSHTML, I simply used the generic Object class. Instantiating anything from MSHTML would introduce different documentModes.

Code example:

'Get document using IE
Dim doc As HTMLDocument
...
set doc = ie.Document

'Old - Extracting rows
Dim element As MSHTML.HTMLGenericElement
For Each element In tableRows

'New - Extracting rows
Dim element As Object
For Each element In tableRows
TechFanDan
  • 3,329
  • 6
  • 46
  • 89