VBA:如何在跳到下一个命令之前给Excel计算时间?

问题描述 投票:0回答:1

我使用彭博的BDP公式来提价,这通常需要1-4秒。但是,VBA在价格拉动完成之前运行下一行代码,导致错误。我想知道是否有办法告诉Excel需要5秒钟才能运行:

Application.Run“RefreshAllStaticData”

完整的代码是:

Sub update()

Application.Run "RefreshAllStaticData"

Worksheets("BB").Range("B2:G1000").Copy
Worksheets("Upload").Range("B2").PasteSpecial Paste:=xlPasteValues

ActiveWorkbook.Save
ActiveWorkbook.Close

End Sub
vba bloomberg
1个回答
0
投票

同样,我们还没有看到你的所有代码(因为我们不知道Application.Run "RefreshAllStaticData"需要什么)但是这个:

Sub update()

Application.Run "RefreshAllStaticData"

'Refresh everything
ActiveWorkbook.RefreshAll
'Wait 5 seconds just in case
Application.Wait (Now + TimeValue("00:00:05"))

Worksheets("BB").Range("B2:G1000").Copy
Worksheets("Upload").Range("B2").PasteSpecial Paste:=xlPasteValues

ActiveWorkbook.Save
ActiveWorkbook.Close

End Sub
© www.soinside.com 2019 - 2024. All rights reserved.