为什么需要打开VBA编辑器才能将数据加载到用户窗体中? [英] Why do I need to have the VBA editor open to load data into a Userform?

查看:271
本文介绍了为什么需要打开VBA编辑器才能将数据加载到用户窗体中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Excel文件,其中VBA宏将数据加载到用户窗体中.

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

如果我在未打开编辑器的情况下运行它,有时它将崩溃并关闭Excel.

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?

来自宏的示例代码:

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)  

推荐答案

此线程为我提供了我的问题的答案:

This thread provided me the answer to my question:

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

很显然,当用户窗体的控件过多时,Excel会遇到内存问题.打开VBA编辑器会以某种方式绕过内存问题,并允许关联的宏正常运行.

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

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

这篇关于为什么需要打开VBA编辑器才能将数据加载到用户窗体中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆