Share via

How to bypass macOS "Sandboxing" for Excel VBA scripts

Fenni Tambou 0 Reputation points
2026-04-14T23:35:31.87+00:00

Always Permission Denied every time my legacy VBA macro tries to use FileSystemObject (FSO) to write log files to a folder outside of the Excel Container on macOS.

How to avoid it

Microsoft 365 and Office | Excel | For business | MacOS
0 comments No comments

2 answers

Sort by: Most helpful
  1. Teddie-D 15,210 Reputation points Microsoft External Staff Moderator
    2026-04-15T00:22:03.47+00:00

    Hi @Fenni Tambou 

    According to Request access to multiple files | Microsoft Learn, this is expected behavior on macOS. 

    Excel for Mac (2016 and later) runs in a sandboxed environment, which means VBA and FileSystemObject (FSO) cannot write outside of Excel’s container unless the user explicitly grants permission using GrantAccessToMultipleFiles

    For scenarios such as unattended logging, the only reliable approach is to write files inside Excel’s sandbox container: 

    • ~/Library/Containers/com.microsoft.Excel/Data 
    • ~/Library/Group Containers/UBF8T346G9.Office 

    Please read more at Sandbox | Mac Excel Automation.

    Granting Excel Full Disk Access in macOS settings may help in certain cases, but this is not documented or supported by Microsoft. You can refer to excel - VB Macros for Office 2016 for Mac require Permissions every time they try to access a file!… 

    This information is provided as a convenience to you. These sites are not controlled by Microsoft, and Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please ensure that you fully understand the risks before using any suggestions from the above link.    

    I hope this information is helpful.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".  

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 


  2. Q&A Assist
    2026-04-14T23:35:45.4333333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Sandboxing cannot be bypassed on Excel for Mac. VBA code is prevented by design from writing arbitrarily to the macOS file system outside locations the sandbox can access.

    To avoid repeated “Permission Denied” errors and user prompts, adapt the macro to work with the supported sandbox mechanisms instead of trying to bypass them:

    1. Use GrantAccessToMultipleFiles for external paths
      • Build an array of POSIX file paths for all log files or folders the macro needs.
      • Call GrantAccessToMultipleFiles(fileArray) once at startup.
      • If the user grants access, the permission is stored with the app and will not be requested again for those paths.
      • Example pattern in VBA:
             Dim ok As Boolean
             Dim files(1 To 1) As String
             
             files(1) = "/Users/username/Logs/mylog.txt"   ' POSIX path
             
             ok = GrantAccessToMultipleFiles(files)
             If Not ok Then
                 MsgBox "Access to log folder was not granted. Logging disabled."
                 Exit Sub
             End If
             
             ' Now use FSO/Open to write to the file
        
      • Ensure the paths are POSIX-style (e.g., /Users/...), not HFS-style.
    2. Keep using FSO, but only after access is granted
      • The sandbox restriction is about file-system permission, not specifically about FSO.
      • Once GrantAccessToMultipleFiles has been approved for a given path, FSO operations to that path should succeed without further prompts.
    3. Designate a fixed log location and get one-time consent
      • Choose a single folder for logs (for example, a folder under the user’s home directory).
      • Request access to that folder path via GrantAccessToMultipleFiles.
      • Reuse that folder for all logging so the user is not prompted for each new file.
    4. Do not attempt to disable sandboxing
      • On Office for Mac, sandboxing is enforced by the OS and cannot be turned off for Excel.
      • The supported pattern is to request and cache access using GrantAccessToMultipleFiles.

    If the macro also needs to interact with other macOS apps or the Finder (for example, to move or manage log files), use AppleScriptTask with an AppleScript placed under ~/Library/Application Scripts/com.microsoft.Excel/, as direct cross-app automation from VBA is also restricted by the sandbox.


    References:

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.