Option Explicit

Function CheckHTMLErrors(ByVal htmlString As String) As Long
    ' This function checks if there are any errors in the HTML tags of a given string
    ' and returns the appropriate Excel color code
    
    Dim objHTML As MSHTML.HTMLDocument
    Set objHTML = New MSHTML.HTMLDocument
    
    ' Load the HTML string into the HTMLDocument object and check for errors
    objHTML.body.innerHTML = htmlString
    If objHTML.parseError.ErrorCode <> 0 Then
        ' An error occurred during parsing, return red color code (ColorIndex = 3)
        CheckHTMLErrors = 3
    Else
        ' No errors, return no fill color (ColorIndex = 0)
        CheckHTMLErrors = 0
    End If
End Function

I'm trying to make a macro to check on the html tags syntax , if it is correct or not.

1

There are 1 best solutions below

0
JohnM On

The error message is telling you that an MSHTML.HTMLDocument object (which is what objHTML is defined as in your code) does not have a parseError Property (and, for info, the parseError Property does not have an ErrorCode Property).

As you have a reference to the MSHTML library in your VBA project, you can see this by (on an empty line) typing objHTML. ... as you type the '.' (dot) then the VBE's IntelliSense will list the available members for you.

AFAIK, setting objHTML.body.innerHTML to any valid String will never raise a VBA error.