excelvbavbe

Why do I need to have the VBA editor open to load data into a Userform?


I have an Excel file in which a VBA macro loads data into a Userform.

It will sometimes crash and close Excel if I run it without the editor open.

How to fix my file so I don't need to first open the editor?

Sample code from the macro:

Public Sub LoadButton_Click()  

    'Policy Information  
    ZoneLatitudeTextBox.Text = Sheets("Saved Policy Values").Cells(2, 2)  
    ZoneLongitudeTextBox.Text = Sheets("Saved Policy Values").Cells(3, 2)  
    TownClassComboBox.Text = Sheets("Saved Policy Values").Cells(4, 2)  

Solution

  • This thread provided me the answer to my question:

    http://www.xtremevbtalk.com/excel/229325-excel-crashes-unless-vba-editor.html

    Apparently Excel runs into memory issues when there is a Userform that has too many controls. Opening VBA editor somehow bypasses the memory issues and allows the associated macro to run properly.

    To automate this process, one simply has to add the following lines of code to the beginning of the macro:

    Application.VBE.MainWindow.Visible = True
    Application.VBE.MainWindow.Visible = False