Sub Protect_Range_Cells() Dim range_1 As Range Set range_1 = Range("B4:E8") Cells.Select Selection.Locked = False range_1.Select Selection.Locked = True ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False End Sub Press F5 to run the VBA code. Click on any of ...
Cells.Locked = True Range("G5:G6, H5, G10:H13").Locked = False ActiveSheet.Protect "12345"...
1)在模块(Module1)中,设计一个名为protectCells的过程,设保护区域(locked ture),也可设未保护、可编辑区域(locked false),并将保护选项设为True。 Sub protectCells() 'Author:http://blog.sina.com.cn/lightonlife 'Macro purpose: set protected/unprotected cells Dim i As Integer Application.ScreenUpdating...
锁定所有单元格:ws.Cells.Locked = True 默认所有单元格都是锁定的。 解锁指定区域:rng.Locked = False 将要保护的区域解锁,以便用户可以修改这些单元格。 保护工作表:ws.Protect password, AllowSelectingLockedCells:=False, AllowDeletingColumns:=True, AllowDeletingRows:=True 保护工作表,并设置相关选项。 运行...
To unprotect the cells, use theUnprotect Sheetfeature (in theHometab). Code Breakdown Sub protect_specific_column():names theSubroutine. Range(“C5”).EntireColumn.Select:selects the entire column in whichC5is located. Selection.Locked = True:locks the selected part of the worksheet. ...
你少了一句end if ActiveSheet.Unprotect Cells.Locked = False '先把所有单元格设置为不锁定的 For i = 3 To 63 If Cells(i, 1) = "正确" Then Cells(i, 2).Locked = True Next ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True 也可以改成以下代码 ActiveSheet....
'清除内容和格式ws.Cells.Clear'清除内容ws.Cells.ClearContents'清除格式ws.Cells.ClearFormats 不过,执行这个代码要谨慎,要防止误操作把别的表的数据给清除了。通常我们在写入一个工作表之前,执行清除操作。13、Delete::删除工作表,谨慎操作,视需要屏蔽警告信息 '复制"明细表",清空复制的表,再把它删除'好象...
要锁定整个工作簿以防止打开,可以在VBA中使用Thisworkbook.password选项。 如果您想保护工作表,则必须首先使用选项Thisworkbook.sheets.cells.locked = True锁定单元格,然后使用选项Thisworkbook.sheets.protect password:="pwd"。 主要搜索这些关键字:Thisworkbook.password或Thisworkbook.Sheets.Cells.Locked。
ws.Cells.ClearFormats 不过,执行这个代码要谨慎,要防止误操作把别的表的数据给清除了。通常我们在写入一个工作表之前,执行清除操作。 13、Delete::删除工作表,谨慎操作,视需要屏蔽警告信息 '复制"明细表",清空复制的表,再把它删除 '好象什么都没有发生,设置中断可以查看过程 ...
打开VBA编辑界面,在代码编辑区复制如下代码:Sub 鱼木混猪()For Each sh In Sheetssh.UnprotectNext '这三行代码是先取消工作表的保护,避免出错For Each sh In Sheetssh.Cells.Locked = Falsesh.Range("A1:A10").Locked = True 'A1:A10为要保护的单元格区域,根据实际情况修改sh.Protect 123 &...