在某些单元格中locking编辑,但没有进一步保护

我试图以防止在某些单元格中编辑的方式来保护我的Excel表格,但禁用了所有其他保护选项。 换句话说,工作表应该具有不受保护的工作表,只在某些禁用单元格的情况下进行单元编辑。

ActiveSheet.Range(Cells(4, 3), Cells(OldRowCount, 7)).Locked = False ActiveSheet.Protect Contents:=True 

我可能需要为.Protect设置一些其他属性,或者我应该完全select一个不同的方法…

提前致谢!

我想这个问题只是,如何在VBA中正确设置这个行为。

F1的快速使用提供了几乎所有的必要条件。 什么是错误的,是Locked的使用,因为它必须对某些细胞是true ,对所有其他细胞是错误的,以便像对待一样。

这是我的解决scheme:

 Public Sub Demo() With ActiveSheet 'Deactivate lock for all cells, so they don't be blocked by protection .Cells.Locked = False 'Activate lock for some cells 'Range(Cells(4, 3), Cells(OldRowCount, 7)).Locked = True .Cells(6, 4).Locked = True If .ProtectContents Then .Unprotect Else 'only contents:=true is really important .Protect _ Password:="", _ Contents:=True, _ DrawingObjects:=False, _ Scenarios:=False, _ UserInterfaceOnly:=True, _ AllowDeletingColumns:=True, _ AllowDeletingRows:=True, _ AllowFiltering:=True, _ AllowFormattingCells:=True, _ AllowFormattingColumns:=True, _ AllowFormattingRows:=True, _ AllowInsertingColumns:=True, _ AllowInsertingHyperlinks:=True, _ AllowInsertingRows:=True, _ AllowSorting:=True, _ AllowUsingPivotTables:=True End If End With End Sub