我使用Office 2011 Mac上,可以确认的是,当子调用sleep
与File not found: kernel32
如果你必须使用在Mac上sleep
命令的替代方法,请共享一个错误将被上调并使用下面的逻辑来选择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
您CA n您还可以使用此代码来设置多达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
我以前见过这个代码...是'Mac'的东西,这将是在条件汇编“代码”中承认?对我来说,仅向Mac用户分发第二个版本的项目是不可行的,所以我不能使用'#CONST Mac = True',然后用'#CONST Mac = False'手动更改并重新分配 –
@Hari - 我以为有一些“内置的”条件编译常量,但似乎并非如此。我测试了我的代码(没有声明“Mac”常量),它似乎工作,但现在我发现即使使用未声明的常量也不会出错 - 它只是给它一个默认值False。 –
@Tim ...感谢您的努力!这给了我我需要知道的东西。 –