When I run the code with debug window open, everything works fine, but when I run the exact same code with debug window closed, weird thing happens, such as it won't copy/paste data into new worksheets, it won't populate values to worksheet from a dictionary, or it will mess up the destination worksheet name/codename.
I accidentally fix the issue once by replacing a function that returns a sheet based on the sheet codename, but this function has been widely used before and didn't have any issue. I really rely on this function in my subs and it would be impossible for me to replace this function in the tool I'm currently working on.
Public Function Code2Sheet(wbkWbk As Workbook, strSheetCodeName As String) As Worksheet
Dim shtSht As Worksheet
For Each shtSht In wbkWbk.Worksheets
If shtSht.CodeName = strSheetCodeName Then
Set Code2Sheet = shtSht
Exit Function
End If
Next shtSht
End Function
Please see one of the subs I have issue with. I highlighted the code that didn't work. It's just not populate value in worksheet when I have debug window closed:
One more weird thing that keeps happening is that when I add a new tab, the new tab wont show up in the object list. I think only if I open the debug window after add the new tab, it will show up