为什么我需要让VBA编辑器窗口打开才能使我的宏工作? [英] Why do I need to have the VBA editor window open for my macro to work?

查看:307
本文介绍了为什么我需要让VBA编辑器窗口打开才能使我的宏工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Excel文件,其中VBA宏将数据加载到Userform中。



如果我首次打开Visual Basic编辑器(通过单击开发人员),宏不会崩溃 - > Visual Basic),但如果我没有编辑器打开,它将有时会崩溃并关闭Excel。



就像打开VBA编辑器激活该宏并启用它正常工作。



我想缩小原因,为什么会这样,如何修复我的文件,所以我不需要先打开编辑器。任何想法?



编辑:我不明白为什么我被downvoted。



宏的示例代码:

  Public Sub LoadButton_Click() 

'政策信息
ZoneLatitudeTextBox.Text =表格(已保存的政策值)。单元格(2,2)
ZoneLongitudeTextBox.Text =表格(已保存的策略值) .Cells(3,2)
TownClassComboBox.Text = Sheets(Saved policy Values)。Cells(4,2)


解决方案

这个线程提供了我的问题的答案:



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



显然,当有一个Userform具有太多控件时,Excel会遇到内存问题。打开VBA编辑器绕过内存问题,并允许关联的宏运行正常。



要自动执行此过程,只需要在开始时添加以下代码行即可的宏:


Application.VBE.MainWindow.Visible = True

Application.VBE.MainWindow.Visible = False



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

The macro never crashes if I first open the Visual Basic editor (by clicking Developer -> Visual Basic), but it will sometimes crash and close Excel if I run it without the editor open.

It's as though opening the VBA editor activates the macro and enables it to work properly.

I'm trying to narrow in on why this is the case and how to fix my file so I don't need to first open the editor. Any ideas?

Edit: I don't understand why i'm being downvoted.

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)  

解决方案

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

这篇关于为什么我需要让VBA编辑器窗口打开才能使我的宏工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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