Excel VBA Error with user access Permission.Add

Dec 0 Reputation points
2024-05-01T10:03:49.6333333+00:00

Hello,

I wrote the following Excel Macro to assign user permission to the Excel file.

Sub Add_Permission() 
 
Dim objUserPerm As Office.UserPermission 
Set objUserPerm = ActiveWorkbook.Permission.Add("******@test.com", msoPermissionChange) 
  
Application.DisplayAlerts = False 
Application.EnableEvents = False 
  
ActiveWorkbook.SaveAs Filename:= _ 
        "C:\Users\Admin\Desktop\" + "order_id_1" + "output_file.xlsx" _ 
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False 
         
Application.DisplayAlerts = True 
Application.EnableEvents = True 
 
End Sub

I have run this macro for moths without any issue, but when I purchased a Microsoft 365 Business Premium license for a new account and logged into Excel with that, I am not able to run the macro anymore. On execution it gives the following error:

Run-time error '-2147023727 (80070491)':

Method 'Add' of object 'Permission' failed

I have searched online for weeks but I cannot find any leads to solve this issue. Did someone experience this?

Thank you.

Windows for business Windows 365 Business
Microsoft 365 and Office Development Other
Microsoft 365 and Office Excel For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Andreas Killer 85 Reputation points Volunteer Moderator
    2024-05-02T13:31:58.1133333+00:00

    I may be wrong and I'm not an expert on access permissions, but isn't the Permission Object only valid / initialized for shared files?

    Andreas.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.