tonydev314
New Member
- Joined
- Oct 1, 2022
- Messages
- 26
- Office Version
- 2013
- Platform
- Windows
I'm busy creating a VBA application in excel. A couple of weeks ago, I made some changes to the code and tried a function and Excel crashed. Nothing was lost in the crash, the recovered file had my latest changes, so I ran it again. Same result. Stepping through the code it got to one point which seemed rather innocuous and it crashed.
I resolved it by going back to the previous version of the file, and copying and pasting in all my code changes from the latest (crashing file).
Now 2 weeks later I have the same issue again - this time it all works perfectly when I step through the code- it just crashes when I'm not debugging.
By putting in place various breakpoints and seeing how far the code gets from the start, I've determined that it's this Sub that causes the crash.
It works perfectly if I put a breakpoint on the ForEach statement, even if I only stop briefly, i.e Immediately hit F5
pChests is a custom collection of a custom object and set as a private variable.
Can anyone shed any light on why this is happening?
I resolved it by going back to the previous version of the file, and copying and pasting in all my code changes from the latest (crashing file).
Now 2 weeks later I have the same issue again - this time it all works perfectly when I step through the code- it just crashes when I'm not debugging.
By putting in place various breakpoints and seeing how far the code gets from the start, I've determined that it's this Sub that causes the crash.
VBA Code:
Private Sub ShowChests()
Dim index As Integer
index = 1
For Each c In pChests
Dim im As image
Set im = Me.Controls("chest" + CStr(index))
im.Picture = LoadPicture(GetImageForChestType(c.Kind))
im.BorderStyle = fmBorderStyleNone
Me.Controls("Frame" + CStr(index)).BackColor = GetBackColorByStatus(c.Status)
index = index + 1
Next
End Sub
It works perfectly if I put a breakpoint on the ForEach statement, even if I only stop briefly, i.e Immediately hit F5
pChests is a custom collection of a custom object and set as a private variable.
Can anyone shed any light on why this is happening?