Excel crashes when clicking object in the locals window od the VB Editor.

strooman

Active Member
Joined
Oct 29, 2013
Messages
333
Office Version
  1. 2016
Platform
  1. Windows
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:

```
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:

Naamloos.png


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?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
It crashes also on my Office 365; I guess that viewer was not designed for any type of data, so if you need to investigate the content of the variable you have to use other commands
 
Upvote 0
I'm using Office 365 (32-bit), and it crashes for me too.

Instead of using the querySelectorAll method, try other methods such as getElementsByTagName or getElementsByClassName.
 
Upvote 0
Well, good that the both of you can reproduce the error. I read another article and members also can reproduce the error and there seems no answer for this 'bug'. I forgot to mention that the code runs fine which is a benefit. If anybody can shed some light over this issue please feel free to inform us.
 
Upvote 0
If you test against a simple website, such as Example Domain, your variable still crashes for any selector. So, a workaround that does not require you to modify your code is to simply inspect through the watch window.

1. Open the watch window
2. Drag and drop the htmlLinks variable
3. Write htmlLinks.length to see how many items it returned
4. Write htmlLinks(0) to inspect the first element and keep inspecting as necessary keeping in mind the length returned

I don't know why it does not support opening the tree for the IHTMLDOMChildrenCollection variable returned by querySelectorAll, but you can still use many other query methods.
 
Upvote 0

Forum statistics

Threads
1,224,873
Messages
6,181,502
Members
453,048
Latest member
engkinooi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top