Friday, February 24, 2012

Test if it is a Mac or a Windows Machine


You can test the operating system like this with VBA code :

Sub WINorMAC()
'Test the OperatingSystem
    If Not Application.OperatingSystem Like "*Mac*" Then
        'I am Windows
        Call My_Windows_Macro
    Else
        'I am a Mac and will test if it is Excel 2011 or higher
        If Val(Application.Version) > 14 Then
            Call My_Mac_Macro
        End If
    End If
End Sub

Or use use conditional compiler constants like this with VBA code :

Sub WINorMAC_2()
'Test the conditional compiler constants
    #If Win32 Or Win64 Then
        'I am Windows
        Call My_Windows_Macro
    #Else
        'I am a Mac and will test if it is Excel 2011 or higher
        If Val(Application.Version) > 14 Then
            Call My_Mac_Macro
        End If
    #End If
End Sub

No comments:

Post a Comment