How to Grant One-Time Access for VBA to Read an External Folder on Mac in Office 2021

梦 尚 0 信誉分
2024-12-17T08:36:44.98+00:00

How to Grant One-Time Access for VBA to Read an External Folder on Mac in Office 2021

When running Excel VBA (7.1) in Office 2021 on a Mac, it needs to read multiple TXT files (over 200) in a specific folder. However, a pop-up message appears requiring additional permissions to access each TXT file, which requires manual approval for every single file.

How can I grant VBA one-time permission to access an entire folder (including all the files within it) on a Mac?

VB
VB
Microsoft 开发的一种面向对象的编程语言,其在 .NET Framework 上实现。 以前称为 Visual Basic .NET。
76 个问题
Office Mac
Office Mac
Office: 一套 Microsoft 高效工作软件,支持常见业务任务,包括文字处理、电子邮件、演示文稿以及数据管理和分析。Mac: 运行 macOS 操作系统的 Apple 个人计算机系列。
12 个问题
0 个注释 无注释
{count} 票

1 个答案

排序依据: 非常有帮助
  1. Emi Zhang-MSFT 26,606 信誉分 Microsoft 供应商
    2024-12-18T01:01:47.7633333+00:00

    Hi,

    Try this command in VBA:

    Sub requestFileAccess()
        'Declare Variables
        Dim fileAccessGranted As Boolean
        Dim filePermissionCandidates
    
        'Create an array with file paths for the permissions that are needed.
        filePermissionCandidates = Array("/Users/YourUsername/Desktop/FolderName/test1.txt", _
                                         "/Users/YourUsername/Desktop/FolderName/test2.txt", _
                                         "/Users/YourUsername/Desktop/FolderName/test3.txt")
    
        'Request access from user.
        fileAccessGranted = GrantAccessToMultipleFiles(filePermissionCandidates)
    
        'Returns true if access is granted; otherwise, false.
        If fileAccessGranted Then
            MsgBox "Access granted to all files."
        Else
            MsgBox "Access denied to one or more files."
        End If
    End Sub
    
    0 个注释 无注释

你的答案

问题作者可以将答案标记为“接受的答案”,这有助于用户了解已解决作者问题的答案。