我使用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 ...感謝您的努力!這給了我我需要知道的東西。 –