vba 我可以在宏运行时显示一些东西吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8013150/
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
Can I display something while a macro is running?
提问by Mike
I have a macro that takes roughly five seconds to execute and I'm using the code Application.ScreenUpdating = False
so it looks like Word has locked up when it's running.
我有一个大约需要五秒钟才能执行的宏,而且我正在使用该代码,Application.ScreenUpdating = False
因此看起来 Word 在运行时已锁定。
I use a message box at the end to tell them it's complete, but I'd like to display an image during its execution that tells the user the macro is running (primarily so they don't get worried, but also because it's nicer to look at).
我在最后使用一个消息框告诉他们它已完成,但我想在其执行期间显示一个图像,告诉用户宏正在运行(主要是为了让他们不担心,但也因为它更好看着)。
There might be an easier way to go about this, but I decided to create an image, create a very basic user form, and simply set my image as its background. Then, I have that user form pop up as soon as the code starts to run.
可能有更简单的方法来解决这个问题,但我决定创建一个图像,创建一个非常基本的用户表单,然后简单地将我的图像设置为背景。然后,一旦代码开始运行,我就会弹出该用户表单。
The problem I'm having is that unless I close it, the rest of the code won't execute. It just hangs until I do something. Is there a way I can get the user form to be displayed without stopping the rest of the process? If not, is there another approach I can take to display an image while the macro is running?
我遇到的问题是,除非我关闭它,否则其余的代码将不会执行。它只是挂起,直到我做某事。有没有一种方法可以在不停止其余过程的情况下显示用户表单?如果没有,是否有另一种方法可以在宏运行时显示图像?
回答by Tim Williams
You can show the userform as non-modal:
您可以将用户表单显示为非模态:
Userform1.Show False
'do more stuff (doesn't wait for form to close)
Userform1.Hide