1

How to parse values between AppleScript and Word (for MAC) VBA? I mean send values to AppleScript from Word VBA and likewise send back values to VBA.

The idea is that a value (string) will be parsed to AppleScript. That will process the value and parse back the output value to Word VBA. The parsed back value have to be an array.

For example,

Dim arrStr() As String
arrStr() = MacScript("<code here>")

?

1 Answer 1

1

The Applescript equivalent of an array is a list variable. It stores values like so {val1, val2, val3} and gets passed back as a string. What you want to do is then use the VBA method Split to parse these into an array. The following example demonstrates this.

Sub TestAppleScript()
    Dim MyScript As String, iNoTimes As Integer, MyArray As Variant
    Dim arrStr() As String

    iNoTimes = 2

     MyScript = "set ArrayReturn to {}" & vbNewLine
     MyScript = MyScript & "repeat with i from 1 to " & iNoTimes & vbNewLine
     MyScript = MyScript & "   set end of ArrayReturn to """"" & vbNewLine
     MyScript = MyScript & "   set item i of ArrayReturn to i" & vbNewLine
     MyScript = MyScript & "end repeat" & vbNewLine
     MyScript = MyScript & "return ArrayReturn"

    MyArray = MacScript(MyScript)

    If MyArray <> "" Then arrStr = Split(MyArray, ",")
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.