nic*_*ick 1 excel vba excel-vba
我正在玩excel VBA而且我正在尝试这样做,所以我可以观看宏滚动细胞.当我尝试使用sleep来缓慢地遍历单元格(使用for循环)时,Excel在大约20次迭代后变得没有响应.它然后挂起直到结束,然后在sub完全执行后返回.
以下是实现它的代码:
Option Explicit
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
Sub test()
Dim i As Integer
For i = 1 To 50
Sleep 250
Selection.Offset(1, 0).Select
Next i
End Sub
Run Code Online (Sandbox Code Playgroud)
我怎么能阻止这种情况发生?
添加DoEvents到你的循环.
Sub test()
Dim i As Integer
For i = 1 To 50
Sleep 250
Selection.Offset(1, 0).Select
DoEvents '/ Add do events to return the resource to interface.
Next i
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
391 次 |
| 最近记录: |