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.
The error message is telling you that an
MSHTML.HTMLDocumentobject (which is whatobjHTMLis defined as in your code) does not have aparseErrorProperty (and, for info, theparseErrorProperty does not have anErrorCodeProperty).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.innerHTMLto any valid String will never raise a VBA error.