Viewing an object in Locals or Watch window causes

2019-06-24 01:53发布

问题:

In Excel when I'm running some code and put a breakpoint in I can look at the values of things in the locals window. In the locals window, when I try to expand a object for the class I've created Excel Crashes with "Microsoft Office Excel has encountered a problem and needs to close. We are sorry for the inconvinience. This also happens if I try to view the object in the watch window.

Any ideas? Or anyone had this before?

Thanks,

Chris

回答1:

Check, check again and recheck your class properties, especially your GET code. I had the same error where expanding the a custom class object during debugging caused Excel to crash. Excel essentially runs those GET properties when you expand the object in the locals window, so they must compile and not cause any runtime errors.

Of course I can't say this definitely caused the OP's error without seeing their code, but for me the error was an extremely simple one where a GET property contained a type mismatch:

Private pAccFullArr() As String

Public Property Get accFullArr() As Variant
    accFullArr = pAccFullArr
End Property

should have been

Private pAccFullArr() As String

Public Property Get accFullArr() As STRING()
    accFullArr = pAccFullArr
End Property