如何在AppleScript和Word(用于MAC)VBA之间解析值?我的意思是从Word VBA向AppleScript发送值,同样将值发送回VBA。
我们的想法是将值(字符串)解析为AppleScript。这将处理该值并将输出值解析回Word VBA。解析后的值必须是一个数组。
例如,
Dim arrStr() As String
arrStr() = MacScript("<code here>")
答案 0 :(得分:1)
数组的Applescript等价物是一个列表变量。它存储像{val1, val2, val3}
这样的值,并作为字符串传回。然后,您要使用VBA方法Split
将这些解析为数组。以下示例演示了这一点。
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