Hi,
I am trying to run some Apple script from Excel using VBA. I know nothing about AppleScript, but I downloaded some code from another forum and when I run it in the AppleScript Editor it works perfectly well. However, when I try to run it in Excel through VBA, it invariably fails, even though I tried several ways already.
Purpose of the script: to create a text file, add some content and save the file
Applescript:
What am I doing wrong?
I am trying to run some Apple script from Excel using VBA. I know nothing about AppleScript, but I downloaded some code from another forum and when I run it in the AppleScript Editor it works perfectly well. However, when I try to run it in Excel through VBA, it invariably fails, even though I tried several ways already.
Purpose of the script: to create a text file, add some content and save the file
Applescript:
Code:
[INDENT]set theFile to ("Macintosh HD:Applications:Microsoft Office 2011:Office:Queries:Test1.txt")
set TheText to "This is the text" & return
open for access file theFile with write permission
set eof file theFile to 0
write TheText to file theFile starting at eof
close access file theFile
set ReadFile to read file theFile[/INDENT]
VBA code to run the same Applescript:
[INDENT]Sub CreateTextFileBis()
Dim strPath As String
Dim strFileName As String
Dim strFullPath As String
Dim strFileContent As String
strPath = "Macintosh HD:Applications:Microsoft Office 2011:Office:Queries:"
strFileName = "test1.txt"
strFullPath = strPath & strFileName
strFileContent = "This is my text"
scriptToRun = scriptToRun & "open for access file " & Chr(34) & strFullPath & Chr(34) & " with write permission" & Chr(13)
scriptToRun = scriptToRun & "set eof file " & Chr(34) & strFullPath & Chr(34) & " to 0" & Chr(13)
scriptToRun = scriptToRun & "write " & Chr(34) & strFileContent & Chr(34) & " to file " & _
Chr(34) & strFullPath & Chr(34) & " starting at eof" & Chr(13)
scriptToRun = scriptToRun & "close access file " & Chr(34) & strFullPath & Chr(34) & Chr(13)
MacScript (scriptToRun)
End Sub[/INDENT]
What am I doing wrong?
Last edited by a moderator: