我有以下VBA代码:
Set wshshell = CreateObject("WScript.Shell")
wshshell.SendKeys "{F3}"
WScript.Sleep 1000
我在WSCript.Sleep
行上收到以下错误:
运行时错误424:需要对象
答案 0 :(得分:1)
WScript.Sleep
仅在脚本主机控件中使用时运行。 VBA不支持它。但是,您可以使用以下示例来延迟。
#If VBA7 Then
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Sub Test()
MsgBox "one"
Sleep 1000
MsgBox "Two"
End Sub