Automate creating .scpt file in application scripts folder on Excel VBA for Mac OS

Copper Contributor

Hello!
I wanted to see if there was a way to use VBA to automate creating a .scpt file in the application scripts folder ("/Users/ComputerName/Library/Application Scripts/com.microsoft.Excel") on MacOS? I am able to read files from that folder using

 

 

myfile = "/Users/" & Environ("USER") & "/Library/Application Scripts/com.microsoft.Excel/test.scpt"
str = ""
Open myfile For Input As #1
Do Until EOF(1)
Line Input #1, textline
str = str & textline
Loop
Close #1

 

 


However I am unable to create a new .scpt file using

 

 

strFile = "/Users/" & Environ("USER") & "/Library/Application Scripts/com.microsoft.Excel/test.scpt"
Open strFile For Output As #1
Print #1, "on ShellEx(shellCmd)" & vbNewLine & vbTab & "do shell script shellCmd end ShellEx"
Close #1

 

 


I run into an error saying "Run-time error '75': Path/File access error".

I know that this might stem from sandboxing on MacOS and that a user needs to grant permission to access that folder. Is there any way to create files in that folder without the user having to do anything? Any help is appreciated. Thank you!

5 Replies
on MacOS? I

how about php or bash on Mac rather than .scpt?

@peiyezhuI'm using a .scpt file to run shell commands. On Excel 2016 and above for Mac, I have only found one way to run a shell command, which is through using Excel's applescript function. Using the applescript function requires a .scpt or .applescript file in the application scripts folder. Are there other ways to run a shell command on Excel 2016 and above for Mac?

Is there any way to create files in that folder without the user having to do anything?

how about php or bash on Mac to create a .scpt file rather than vba which may repoert grant permission.
My Excel spreadsheet is being used like an self contained app, so I want to use VBA to run all the necessary things.

try change folder access rights
e.g.
/Library/WebServer/Documents
is your path.

sudo chmod -R 0777 /Library/WebServer/Documents





https://blog.csdn.net/qq_39997939/article/details/122893354
https://www.cnblogs.com/phpyangbo/p/15538981.html
https://blog.csdn.net/weixin_42274846/article/details/128034612