VBA Code to Protect Excel Sheet
VBA Code to Protect Excel SheetExample:
Sheet1.Unprotect "123" Sheet1.Range("A1").Value = "ABC" Sheet1.Protect "123"
Sheet1.Protect Password:="123", UserInterfaceOnly:=True
In the code you will notice that UserInterfaceOnly has been passed as True that does the trick. If you protect a sheet with UserInterfaceOnly as True then Excel allows VBA to write data on the sheet without unprotecting it.
Please note that this code needs to be executed once before you share the file.