VBA Sleep Doesn't Work

后端 未结 7 1302
礼貌的吻别
礼貌的吻别 2020-12-03 10:57

I know I\'m doing something wrong here. I\'m trying to use the sleep function to delay my code, but I get \"Sub or Function not defined\" error. Any tips?

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 11:18

    VBA does not have a Sleep function.

    You can import it from Kernel32.dll like this:

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

    Note that this will freeze the application.
    You can also call DoEvents in a While loop, which won't freeze the application.

提交回复
热议问题