Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3009|回复: 2

怎么实现在按下保存的时候 去掉保护。

[复制链接]
发表于 2014-2-26 16:51 | 显示全部楼层 |阅读模式
5学分
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ir As Integer
Dim c As Range

  ActiveSheet.Unprotect
  ir = [d65536].End(xlUp).Row
  Cells.Locked = False
  For Each c In Range("d1:d" & ir)
    If c.Value = Range("F2").value Then Range("A" & c.Row & ":C" & c.Row).Locked = True
  Next
  ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

怎么实现在按下保存的时候 去掉保护。

发表于 2014-2-26 16:58 | 显示全部楼层
本帖最后由 baksy 于 2014-2-26 17:01 编辑

    代码 ;Cells.Locked = False  

Private Sub Worksheet_Change(ByVal Target As Range)
Dim ir As Integer
Dim c As Range
Cells.Locked = False  '取消保护
  ActiveSheet.Unprotect
  ir = [d65536].End(xlUp).Row
  For Each c In Range("d1:d" & ir)
    If c.Value = Range("F2").value Then Range("A" & c.Row & ":C" & c.Row).Locked = True
  Next
  ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

回复

使用道具 举报

 楼主| 发表于 2014-3-25 16:56 | 显示全部楼层
这个不行啊,运行不来,我要是在工作处理完,在按下保存文件的时候保护取消掉;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-6-1 13:52 , Processed in 0.173945 second(s), 4 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表