1
votes

I have run the following program on vba excel 2010 32 bit computer :

Declare Sub sleep Lib "kernel32" (ByVal dwmilliseconds As Long)

Sub game()

i = 0

Do

i = i + 1

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

Loop Until i > 10

End Sub

But, after running, it shows me the following error :

"Can't find dll entry point sleep in kernel32"

Can somebody please tell me what I should do next to remove the error?

Thanks for the effort.

2
Try capital "S" in Sleeptransistor1

2 Answers

1
votes

Instead of sleep 500 you might want to use:

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

@Transistor is correct. You have to use capital "S". All API declarations are case sensitive.

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

An alternative to Sleep is to use the function Wait which I created few years ago and I still use it.

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