vba VBA表格消失

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11422114/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:50:06  来源:igfitidea点击:

VBA Form disappearing

exceluser-interfacevbamode

提问by user1251858

I have a VBA form that when I click on it, performs some long calculations (a few seconds to several seconds long) and then displays the results on frames in the form. However, once every so often, the form hides on me and I need to click around to the VBA editor and back to the sheet to make it display again

我有一个 VBA 表单,当我点击它时,会执行一些长时间的计算(几秒到几秒),然后在表单中的帧上显示结果。但是,每隔一段时间,表单就会隐藏在我身上,我需要单击到 VBA 编辑器并返回到工作表以使其再次显示

I have

我有

Me.Repaint 

at the end of the calculations on the form but it still doesn't help

在表格上的计算结束时,但它仍然没有帮助

I also tried disabling the "EnableCalculation" attribute of the main sheet, but still no use

我也尝试禁用主表的“EnableCalculation”属性,但仍然没有用

Anyone ever run into something like this? Do I need to load the form in some special way?

有没有人遇到过这样的事情?我需要以某种特殊方式加载表单吗?

回答by Neil Ward

I have had the same problem. When saving an Excel workbook by clicking on a command button on a modeless Userform, the form disappears as the code completes.

我曾经也有过一样的问题。通过单击无模式用户窗体上的命令按钮保存 Excel 工作簿时,该窗体会随着代码的完成而消失。

I read that the problem was due to some inter-compatible changes that Microsoft has made and found some very elaborate solutions involving a lot of complex code that I was unable to integrate into my project. However, I did find a very quick workaround.

我读到问题是由于 Microsoft 所做的一些相互兼容的更改,并找到了一些非常复杂的解决方案,其中涉及许多我无法集成到我的项目中的复杂代码。但是,我确实找到了一个非常快速的解决方法。

In my case the Userform only disappeared when the code executed the End Subcommand of the command button's code. I simply added an Exit Subimmediately before it and the Userform no longer disappears.

在我的情况下,用户窗体仅在代码执行End Sub命令按钮代码的命令时消失。我只是Exit Sub在它之前添加了一个,用户表单不再消失。

回答by Sorceri

Have you tried turning off and on screen updating so Excel is not redrawing the screen with each change.

您是否尝试过关闭和打开屏幕更新,以便 Excel 不会在每次更改时重新绘制屏幕。

sub doSomthing()
Application.ScreenUpdating = False
'do something
Application.ScreenUpdating = True
end sub

回答by Tony

The form disappears because Microsoft has changed the model by which forms are owned by a 'superior' process (Excel in your case). I have the same problem and also cannot overcome it.

表单消失是因为 Microsoft 更改了表单由“高级”进程(在您的情况下为 Excel)拥有的模型。我有同样的问题,也无法克服它。

Just sit tight until Microsoft decides that it is worth their effort to fix yet another introduced and untested problem by making changes to something that already worked.

只需坐稳,直到 Microsoft 决定通过对已经有效的东西进行更改来解决另一个引入和未经测试的问题是值得的。

回答by danielpiestrak

Try experimenting with the following two lines of code instead of the repaint.

尝试使用以下两行代码代替重绘。

Me.Show

And/Or:

和/或:

Me.SetFocus

Hopefully, one of these will work for you!

希望其中之一对您有用!

回答by Michiel

In my case I had to use all these to make it happen. (frmGUI is my form) DoEvents
frmGUI.Repaint frmGUI.Show

就我而言,我必须使用所有这些来实现它。(frmGUI 是我的形式) DoEvents
frmGUI.Repaint frmGUI.Show

回答by mountainclimber

With Office 2013 and Windows 7, simply adding DoEventsright before the end of the sub(where the form disappeared) kept the form open. Nothing else needed....for my situation.

使用 Office 2013 和 Windows 7,只需DoEvents在结尾sub(表单消失的地方)之前添加即可保持表单打开。没有其他需要......对于我的情况。