vba Excel 在调用另一个宏之前等待一个宏完成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1703576/
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 10:57:25  来源:igfitidea点击:

Excel waiting for one macro to finish before calling another

excelexcel-vbavba

提问by noel_g

I'm using Application run to call several macros in order like this.

我正在使用 Application run 以这样的顺序调用几个宏。

Sub Run_All_Macros()
  Application.Run ("Macro_1")
  Application.Run ("Macro_1")
End Sub

When I start Run_All_Macros, all the macros run in parallel. Is there a way to wait for the first macro to complete before the second is started?

当我启动 Run_All_Macros 时,所有的宏都并行运行。有没有办法在第二个宏开始之前等待第一个宏完成?

回答by guitarthrower

If you step through the macros (Use F8) you should see that they are running in order and not simultaneously.

如果您逐步执行宏(使用 F8),您应该会看到它们按顺序运行,而不是同时运行。

I use the step through method to watch exactly what is happening and in what order. I often find I've included an error in logic, or something else, that doesn't give the desired result.

我使用逐步方法来准确观察正在发生的事情以及发生的顺序。我经常发现我在逻辑中包含了一个错误,或者其他一些没有给出预期结果的错误。