Microsoft Excel

Ron de Bruin
Excel Automation

Microsoft MVP Program

Detect Mac OS X version number

Sometimes as a developer you want to be sure that the Mac your VBA code is running on have the correct Mac OS X version installed so your code is working correct. With the macro example below you can test the Mac OS version.

On this moment my Mac OS X version = 10.12 (9-Oct-2016)

Mac OS X 10.0     Cheetah
Mac OS X 10.1     Puma
Mac OS X 10.2     Jaguar
Mac OS X 10.3     Panther
Mac OS X 10.4     Tiger
Mac OS X 10.5     Leopard
Mac OS X 10.6     Snow Leopard
Mac OS X 10.7     Lion
OS X 10.8            Mountain Lion
OS X 10.9            Mavericks
OS X 10.10          Yosemite
OS X 10.11          El Capitan
macOS 10.12       Sierra

 

Working in Office 2011 and 2016

In the Mac Office 2016 version they changed the string that is returned by Application.OperatingSystem so I looked for another solution that is working in Office 2011 and up in every Office program. The macro below test if Sierra is installed.

Sub TestMacOSXVersion()
'Example to test if Sierra or higher is installed (10.12)
    Dim OSstring As String
    Dim MySplit As Variant

    OSstring = MacScript("do shell script ""sw_vers -productVersion""")
    MySplit = Split(OSstring, ".")

    If Val(MySplit(0)) = 10 And Val(MySplit(1)) >= 12 Then
        MsgBox "This is Sierra or higher"
    Else
        MsgBox "Sorry you not have Sierra or higher installed"
    End If

    ' Note : If you want to know the exact Update number you can use
    ' also Val(MySplit(2)) in the If line if that is important

    'For information and testing only I add the three lines below
    MsgBox MySplit(0)
    MsgBox MySplit(1)
    'MsgBox MySplit(2)
End Sub

 

Only working in Office 2011

Note: Application.OperatingSystem is not working in Word and Application.System.Version not in Excel and PowerPoint, that's the reason I have two macro examples below for Office 2011. But use the example above that is working in 2011 and 2016.

Excel and PowerPoint

Sub TestMacOSXVersionExcelPowerPoint()
'Example to test if Mavericks or higher is installed (10.9.?)
    Dim OSstring As String
    Dim OSVersion As String
    Dim MySplit As Variant

    OSstring = Application.OperatingSystem
    OSVersion = Right(OSstring, Len(OSstring) - InStrRev(OSstring, " ", , 1))
    MySplit = Split(OSVersion, ".")

    If Val(MySplit(0)) = 10 And Val(MySplit(1)) >= 9 Then
        MsgBox "This is Mavericks or higher"
    Else
        MsgBox "Sorry you not have Mavericks or higher installed"
    End If

    ' Note : If you want to know the exact Update number you can use
    ' also Val(MySplit(2)) in the If line if that is important

    'For information and testing only I add the three lines below
    MsgBox MySplit(0)
    MsgBox MySplit(1)
    MsgBox MySplit(2)
End Sub

Note: The next OS X will be Yosemite 10.10 so Val(MySplit(1)) >= 9 will also be true

 

Word

Sub TestMacOSXVersionWord()
'Example to test if Mavericks or higher is installed (10.9.?)
    Dim OSVersion As String
    Dim MySplit As Variant

    OSVersion = Application.System.Version
    MySplit = Split(OSVersion, ".")

    If Val(MySplit(0)) = 10 And Val(MySplit(1)) >= 9 Then
        MsgBox "This is Mavericks or higher"
    Else
        MsgBox "Sorry you not have Mavericks or higher installed"
    End If

    ' Note : If you want to know the exact Update number you can use
    ' also Val(MySplit(2)) in the If line if that is important

    'For information and testing only I add the three lines below
    MsgBox MySplit(0)
    MsgBox MySplit(1)
    MsgBox MySplit(2)
End Sub

Note: The next OS X will be Yosemite 10.10 so Val(MySplit(1)) >= 9 will also be true