Forum Discussion

oatmeal123's avatar
oatmeal123
Copper Contributor
Jan 10, 2023

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

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

  • peiyezhu's avatar
    peiyezhu
    Bronze Contributor
    on MacOS? I

    how about php or bash on Mac rather than .scpt?
    • oatmeal123's avatar
      oatmeal123
      Copper Contributor

      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?

      • peiyezhu's avatar
        peiyezhu
        Bronze Contributor
        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.

Resources