Forum Discussion

saravanan24's avatar
saravanan24
Copper Contributor
May 04, 2023

User Access in excel sheets with macro's

Hi,

I am seeking a way to prevent writing on a sheet at the user level without using a protect password method, since we use macro's to transfer data from one sheet to another even its protected.

When attempting to transfer data from one sheet to another after protecting the sheet, an error 400 is generated.

Could you please provide us the way to solve this.

 

Thanks

2 Replies

  • saravanan24 

    One option is to protect the sheet, and then unprotect it at the beginning of a macro, and reprotect it at the end.

    Another option is to protect the sheet in the Workbook_Open event procedure in the ThisWorkbook module with the UserInterfaceOnly argument set to True:

    Private Sub Workbook_Open()
        Worksheets("Sheet1").Protect Password:="Secret", UserInterfaceOnly:=True
    End Sub

    VBA code should then be able to manipulate the protected sheet without causing an error.

Resources