VB Macros for Office 2016 for Mac require permission every time they try to access the file! Is there a way to get around this behavior?

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

+3


source to share


1 answer


Unlike VB macros in Office for Mac 2011, VB macros in Office 2016 for Mac do not have access to external files by default. Office 2016 for Mac apps are sandboxed and therefore lack permissions to access external files.

The existing macro file commands have been changed to offer the user access to the files if the application no longer has access to it. This means that macros that access external files cannot be run unattended; they will require the user of the interaction to approve access to the files the first time they access each file.

Developers should use the GrantAccessToMultipleFiles command(see next section) to avoid this. This command allows your application to get permission for all files in one go, thus avoiding difficult user use.

GrantAccessToMultipleFiles
This allows you to enter an array of file paths and ask the user for permission to access them.
 

Boolean  GrantAccessToMultipleFiles(fileArray) 

      

  • Parameters

    • fileArray is an array of POSIX file paths.
  • Return values

    • True. User grants permissions to files.
    • False - User denies permission to files.



Note. Once permission is granted, the permissions are stored in the app and the user no longer needs to grant permission to that file.

Example:

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

      

+5


source







All Articles