I have a Mac using Office 2011 and can confirm that an error will be raised when the sub calls sleep
with File not found: kernel32
If you have an alternative approach to use the sleep
command in Mac, please share and use the below logic to select Mac or 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
You can also use this code to set a timer with up to 7 decimals, which works for both Mac and 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