When I want to view an object (the `htmlLinks` variable) in the locals window of the VB Editor by clicking the plus (+) sign, Excel crashes. The message I get: *"Microsoft Office Excel has encountered a problem and needs to close. We are sorry for the inconvinience."*
To reproduce the crash I use this code:
```
```
The error occurs when clicking the plus sign (+) before the `htmlLinks` variable in the locals window. See screen below:
I use a completely blank workbook with only the presented code. My Office version is:
Microsoft Office Professional Plus 2016 on a Windows 11 system.
What I did:
- Start with a blank and new workbook from scratch
- To reproduce the error I looked (and found) some basic code which I used for testing.
- Read different forums but that didn't give me any clues to work with or understand the problem.
Any ideas how to solve this? I mean, that Excel doesn't crash?
To reproduce the crash I use this code:
```
VBA Code:
Sub test()
Dim xmlReq As MSXML2.XMLHTTP60
Dim htmlDoc As MSHTML.HTMLDocument
Dim htmlLinks As MSHTML.IHTMLDOMChildrenCollection
Dim Url As String
Dim resp As String
Dim linkIndex As Long
Url = "https://www.mrexcel.com"
Set xmlReq = New MSXML2.XMLHTTP60
Set htmlDoc = New MSHTML.HTMLDocument
With xmlReq
.Open "GET", Url, False
.send
Do While .readyState <> 4
DoEvents
Loop
If .Status <> 200 Then
MsgBox "Error " & .Status & ": " & .statusText
Exit Sub
End If
resp = .responseText
End With
htmlDoc.body.innerHTML = resp
Set htmlLinks = htmlDoc.querySelectorAll("a.nav-link") ' use the querySelector to search by tag and class
With htmlLinks
For linkIndex = 0 To .Length - 1
If Trim$(.Item(linkIndex).innerText) = "Message Board" Then
Debug.Print .Item(linkIndex).href
Exit For
End If
Next linkIndex
End With
Set xmlReq = Nothing
Set htmlDoc = Nothing
Set htmlLinks = Nothing
End Sub
The error occurs when clicking the plus sign (+) before the `htmlLinks` variable in the locals window. See screen below:
I use a completely blank workbook with only the presented code. My Office version is:
Microsoft Office Professional Plus 2016 on a Windows 11 system.
What I did:
- Start with a blank and new workbook from scratch
- To reproduce the error I looked (and found) some basic code which I used for testing.
- Read different forums but that didn't give me any clues to work with or understand the problem.
Any ideas how to solve this? I mean, that Excel doesn't crash?