excel - Excel VBA中mac的睡眠等效项
问题描述
我想在 Excel 的 macOS VBA 编辑器中添加 500 毫秒的等待块。我知道
Application.Wait (Now + TimeValue("0:00:01"))
有效,但这不能低于 1 秒。我也尝试过 sleep 命令:
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
...
Sleep 500
但这给了我一个错误说
File Not Found "kernel32"
有什么办法可以做到这一点?
解决方案
这适用于 Windows 和 Mac:
Option Explicit
#If Mac Then
#If VBA7 Then
Public Declare PtrSafe Sub USleep Lib "/usr/lib/libc.dylib" Alias "usleep" (ByVal dwMicroseconds As Long)
#Else
Public Declare Sub USleep Lib "/usr/lib/libc.dylib" Alias "usleep" (ByVal dwMicroseconds As Long)
#End If
#Else 'Windows
#If VBA7 Then
Private Declare PtrSafe Sub MSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
#Else
Private Declare Sub MSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
#End If
#End If
Public Sub Sleep(ByVal dwMilliseconds As Long)
#If Mac Then
USleep dwMilliseconds * 1000&
#Else
MSleep dwMilliseconds
#End If
End Sub
推荐阅读
- html - 由于路由错误,刷新 Angular 页面会破坏网页
- sql - 使用多个条件 AND / OR 的性能
- javascript - 为什么 JavaScript Promise Catch 没有被触发
- html - web-publisher 如何阻止 Amazon Affiliate DEEP-LINKS 在 Amazon App 中打开
- python - 如何根据标签绘制具有不同颜色的配对数据
- java - 在 RecyclerView 中的扩展项目上使用带有 ChangeBounds 的 TransitionManager 与 layout_height: match_constraint 结合使用会产生奇怪的视觉效果
- c++ - C ++中int的最小大小是多少?
- tizen - 如何在三星智能电视的 Tizen 浏览器中调试代码
- c++ - 为什么我不能使用实现 operator unsigned int() 的类作为 Visual C++ 32 位中的数组索引?
- python - Python v/s MATLAB 中的 SVD 命令