Microsoft 365 和 Office | 安装、兑换、激活 | 商业版 | MacOS
Microsoft 365 中用于设置 Office 应用、兑换产品密钥和激活许可证的过程。
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?
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