Microsoft Excel

Ron de Bruin
Excel Automation

Microsoft MVP Program

Read value from Mac Excel Preference file

Sometimes as a developer you want to know what is in the file.

The example below will only work when you use the new AppleScriptTask function in Excel 2016 and higher. Below you will find the appescript that you must save into a script fille named ReadPlistValue and copy it in the correct location, and the VBA macro that you can use to run the script.

Follow the steps from this page to get it working :

The Applescript

--Ron de Bruin,
--Applescripts for reading values in the Excel plist file

on GetPlistValue(paramstring)
    set {fieldvalue1, fieldValue2} to SplitString(paramstring, ";")
    tell application "System Events"
        set PLRoot to property list file (fieldvalue1)
        return value of property list item fieldValue2 of PLRoot
    end tell
end GetPlistValue

on SplitString(TheBigString, fieldSeparator)
    tell AppleScript
        set oldTID to text item delimiters
        set text item delimiters to fieldSeparator
        set theItems to text items of TheBigString
        set text item delimiters to oldTID
    end tell
    return theItems
end SplitString


The VBA macro

Sub ReadPlistValue()
    Dim PlistPathString As String
    Dim PlistValueString As String
    Dim CompleteString As String
    Dim RunMyScript As String

    'This point to the Excel plist file, no need to change it
    PlistPathString = MacScript("return (path to Home folder as text)") & ""
    'Fill in the value you want to read
    PlistValueString = "SessionLongBuildNumber"

    On Error Resume Next
    CompleteString = PlistPathString & ";" & PlistValueString
    RunMyScript = AppleScriptTask("ReadPlistValue.scpt", "GetPlistValue", CompleteString)
    On Error GoTo 0

    MsgBox PlistValueString & " = " & RunMyScript
End Sub


See also this page if you want to save/read information from your own files in a plist file.

SaveSetting, GetSetting and DeleteSetting on Mac