2014-10-18 163 views
1

我已经运行VBA下面的程序Excel 2010的32位计算机:休眠功能错误453

声明子睡眠库 “KERNEL32”(BYVAL dwmilliseconds长)

子游戏()

I = 0

i = i + 1 

Cells(i, 1).Interior.Color = RGB(100, 0, 0) 
sleep 500 

循环,直到我> 10

末次

但是,运行后,它让我看到以下错误:

“无法找到KERNEL32 DLL入口点睡眠”

有人可以告诉我接下来应该怎么做,以消除错误?

感谢您的努力。

+1

在睡眠中尝试大写“S” – transistor1 2014-10-18 20:20:28

回答

1

而是睡眠500的,你可能要使用:

Application.Wait (Now + TimeValue("0:00:05")) 
+1

+ 1 Application.Wait是另一个不错的选择 – 2014-10-18 22:33:12

0

@Transistor是正确的。你必须使用大写字母“S”。所有API声明都区分大小写。

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 

的替代Sleep是使用我创造了几年前,我仍然使用它的功能Wait

Sub Sample() 
    i = 0 
    Do 
     i = i + 1 
     Cells(i, 1).Interior.Color = RGB(100, 0, 0) 
     Wait 1 
    Loop Until i > 10 
End Sub 

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