Prevent user from deleting a particular sheet

前端 未结 6 1260
春和景丽
春和景丽 2020-12-10 06:54

Protecting workbook structure will prevent a user from deleting sheets. But how could I (using VBA) prevent a user from deleting a particular sheet I designate? I\'

6条回答
  •  囚心锁ツ
    2020-12-10 07:10

    I found this solution, similar to Dan's, on ExtendOffice.com. Put this code on the Worksheet's module:

    Private Sub Worksheet_Activate()
    ThisWorkbook.Protect "yourpassword"
    End Sub
    
    Private Sub Worksheet_Deactivate()
    ThisWorkbook.Unprotect "yourpassword"
    End Sub
    

    When you activate the sheet in question, the whole workbook is protected, and the "Delete" option is grayed out. When you switch to any other sheet, the workbook is free again. It's subtle because you only notice the change when you go to the "safe" sheet.

提交回复
热议问题