Not enough memory crash when loading VBA userform

前端 未结 2 534
無奈伤痛
無奈伤痛 2021-01-01 07:47

Background:

I have a VBA userform with ~1050 checkboxes, and ~100 labels, all populated from the active Sheet. The labels are taken directly from t

2条回答
  •  梦毁少年i
    2021-01-01 08:01

    I once fixed a crashing Excel form with many controls by making sure the code always refers all controls via the Controls collection:

    Me.Controls("Cond1").Caption = .Cells(r, c + 1)
    

    and never via their code names:

    Me.Cond1.Caption = .Cells(r, c + 1)
    

    It was weird, but it worked.
    Try replacing all your Stb.Cond1.Caption with Stb.Controls("Cond1").Caption etc.


    That was about 15 years ago, and up until today it remained unclear to me why it worked and why on Earth I even thought that utilising Controls in this way might have something to do with fixing it. As I learned today, it is a long standing limitation in Excel on the number of controls that can be addressed directly by their name - a poorly documented limitation, and a poorly implemented one too, as such a limitation must produce a compilation error rather than a runtime error at a random moment.

提交回复
热议问题