Office 2010 for Mac的VB宏需要每次尝试访问文件时都有权限!有没有办法摆脱这种行为? [英] VB Macros for Office 2016 for Mac require Permissions every time they try to access a file! Is there any way to get around this behavior?

查看:1297
本文介绍了Office 2010 for Mac的VB宏需要每次尝试访问文件时都有权限!有没有办法摆脱这种行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Office 2016中的任何VB宏显示一个对话框,供用户要求权限,每次宏尝试访问一个文件!有没有办法避免这种情况。

Any VB Macro in Office 2016 shows a dialog box to the user asking for permission, every time the Macro tries to access a file! Is there a way to avoid it.

推荐答案

与Office Mac for Mac 2011中的VB宏不同,Office 2010 Mac版的VB宏默认情况下无法访问外部文件。 Office 2016 for Mac应用程序是沙盒,因此他们缺乏访问外部文件所需的权限。

如果应用程序尚未访问,现有的宏文件命令将被更改以提示用户进行文件访问。这意味着访问外部文件的宏无法无人值守运行;首次引用每个文件时,他们将需要用户交互来批准文件访问。


开发人员应使用 GrantAccessToMultipleFiles 命令(请参阅以下部分)以避免此类体验。此命令可让您的应用程序一次获得所有文件的权限,从而避免了难以获得的用户体验。


GrantAccessToMultipleFiles

这可以让您输入文件路径数组,并提示用户访问权限。


Unlike VB Macros in Office for Mac 2011, VB Macros in Office 2016 for Mac do not have access to external files by default. The Office 2016 for Mac apps are sandboxed and hence they lack the required permissions to access external files.

Existing macro file commands are changed to prompt the user for file access if the app doesn’t already have access to it. This means that macros that access external files cannot run unattended; they will require user interaction to approve file access the first time each file is referenced.

Developers should use the GrantAccessToMultipleFiles command (see following section) to avoid this experience. This command lets your app get permission for all the files at one time, thereby avoiding a difficult user experience.

GrantAccessToMultipleFiles
This lets you input an array of file paths and prompt the user for permission to access them.

Boolean  GrantAccessToMultipleFiles(fileArray) 




  • 参数

    • Parameters


      • fileArray - POSIX文件路径数组。

      返回值


      • True - 用户授予文件权限。

      • False - 用户拒绝对文件的权限。



      注意:权限与应用程序一起存储,用户不需要向文件授予权限。

      示例:

      Sub requestFileAccess()  
        
      'Declare Variables  
          Dim fileAccessGranted As Boolean  
          Dim filePermissionCandidates 
        
       'Create an array with file paths for which permissions are needed  
          filePermissionCandidates = Array("/Users/<user>/Desktop/test1.txt", "/Users/<user>/Desktop/test2.txt") 
        
      'Request Access from User  
          fileAccessGranted = GrantAccessToMultipleFiles(filePermissionCandidates) 'returns true if access granted, false otherwise  
            
        
      End Sub
      

      这篇关于Office 2010 for Mac的VB宏需要每次尝试访问文件时都有权限!有没有办法摆脱这种行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆