请求访问多个文件Request access to multiple files

适用于:Excel for Mac | PowerPoint for Mac | Word for Mac | Office 2016 for MacApplies to: Excel for Mac | PowerPoint for Mac | Word for Mac | Office 2016 for Mac

使用GrantAccessToMultipleFiles命令在 Office 2016 for Mac 解决方案中一次请求对多个文件的访问权限。Use the GrantAccessToMultipleFiles command to request access to multiple files at once in your Office 2016 for Mac solution.

与 Office for Mac 2011 中的 VBA 宏不同,默认情况下,Office 2016 for Mac 中的 VBA 宏不能访问外部文件。Unlike VBA macros in Office for Mac 2011, VBA macros in Office 2016 for Mac don't have access to external files by default. 由于 Office 2016 for Mac 应用程序已经过沙盒,因此它们不具有访问外部文件的权限。Because the Office 2016 for Mac apps are sandboxed, they do not have permission to access external files.

现有的宏文件命令提示用户在应用程序无法访问文件时,是否有权访问该文件。Existing macro file commands prompt the user for permission to access a file if the app doesn't have access to it. 这意味着,访问外部文件的宏不能以无人值守的方式运行。This means that macros that access external files cannot run unattended. 用户在第一次引用每个文件时必须批准文件访问。The user must approve file access the first time each file is referenced. 您可以使用GrantAccessToMultipleFiles命令来最大限度地减少提示数,以便改进用户体验。You can use the GrantAccessToMultipleFiles command to minimize the number of prompts in order to improve the user experience.

GrantAccessToMultipleFiles 命令GrantAccessToMultipleFiles command

使用GrantAccessToMultipleFiles命令输入文件路径的数组,并提示用户有权访问它们。Use the GrantAccessToMultipleFiles command to input an array of file paths and prompt the user for permission to access them.

Boolean  GrantAccessToMultipleFiles(fileArray) 
参数Parameter 说明Description
fileArrayfileArray 由 POSIX 文件路径组成的数组An array of POSIX file paths

该命令将返回用户是否已授予权限。The command returns whether the user granted permission or not.

返回值Return value 说明Description
TrueTrue 用户授予对文件的权限。The user grants permission to the files.
FalseFalse 用户拒绝对文件的权限。The user denies permission to the files.

备注

用户授予权限后,这些权限将与应用程序一起存储。After the user grants permissions, the permissions are stored with the app. 用户无需再次向该文件授予权限。The user doesn't need to grant permission to the file again.

示例Example

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//Desktop/test1.txt", "/Users//Desktop/test2.txt") 

    'Request access from user.  
    fileAccessGranted = GrantAccessToMultipleFiles(filePermissionCandidates) 
    'Returns true if access is granted; otherwise, false. 
End Sub

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.