gpt4 book ai didi

vba - 在宏中指定 Action 顺序?

转载 作者:行者123 更新时间:2023-12-04 20:45:08 25 4
gpt4 key购买 nike

我在工作表中编写了一系列宏,它们按顺序工作以通过 api 下载数据,然后分析和格式化数据。

我的目标是将六个命令按钮合二为一。但是当我这样做时,虽然我只是从一个子复制并粘贴到另一个子中,结果是不同的。

我的猜测是后面的命令(取决于前面步骤的完成)不会等待前面的命令完成,尤其是数据下载。

这对任何有 VBA 经验的人是否有意义,或者 vba 代码是否总是按顺序和耐心地评估?

是否有命令在不同代码段的执行之间添加时间跨度?

不需要代码帮助,如果存在的话,只是命令的指南。

谢谢。

最佳答案

Does this make sense to anyone more experienced with VBA or does vba code always evaluate sequentially and patiently?



依次……是的。耐心地?绝对是大 NO .否则我们就不必使用 DoEvents :)

Is there a command to add a time span between the execution of different pieces of the code? Don't really need code help, just a guide to the command if it exists.



就像我上面提到的,你可以使用 Doevents或者这个 Wait我使用的功能。
Sub Sample()
MsgBox "Hello"

Wait 5 '<~~ Wait for 5 seconds

MsgBox "World"
End Sub

Private Sub Wait(ByVal nSec As Long)
nSec = nSec + Timer
While nSec > Timer
DoEvents
Wend
End Sub

关于vba - 在宏中指定 Action 顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20227751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com