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@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.

Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,529 questions
Windows 365 Business
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,574 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Andreas Killer 80 Reputation points
    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.