我有一台使用 Office 2011 的 Mac,并且可以确认当 sub 调用时会引发sleep
错误File not found: kernel32
如果您有其他方法sleep
在 Mac 中使用该命令,请分享并使用以下逻辑选择 Mac 或 Windows:
Public Sub WINorMAC()
'Test for the operating system.
If Not Application.OperatingSystem Like "*Mac*" Then
'Is Windows.
Call Windows_specific_function()
Else
'Is a Mac and will test if running Excel 2011 or higher.
If Val(Application.Version) > 14 Then
Call Mac_specific_function()
End If
End If
End Sub
您还可以使用此代码设置最多 7 位小数的计时器,适用于 Mac 和 Windows:
'---------TIMER MACRO--------'
'PURPOSE: Determine how many seconds it took for code to completely run
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
Dim StartTime As Double
Dim SecondsElapsed As Double
Dim minutesElapsed As Double
'Remember time when macro starts
StartTime = Timer
'*************************************
'------Start to run code--------'
'*************************************
Your code goes here
'*************************************
'----------End code----------'
'*************************************
'Determine how many seconds code took to run
'If you want in seconds with two decimals, use this line:
'SecondsElapsed = Round(Timer - StartTime, 2)
'If you want with up to 7 decimals, use this line:
SecondsElapsed = Timer - StartTime
'Notify user how long the macro took
If SecondsElapsed > 60 Then
minutesElapsed = Int(SecondsElapsed / 60)
SecondsElapsed = Int(SecondsElapsed - (minutesElapsed * 60))
Msgbox "This code ran successfully in " & minutesElapsed & " minutes and " & SecondsElapsed & " seconds", vbInformation
Else
Msgbox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation
End If