保护除少数单元格之外的工作簿 [英] Protecting a workbook except for a few cells

查看:65
本文介绍了保护除少数单元格之外的工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保护我的工作簿,但保留了一些不受用户输入保护的单元格.我正在尝试的代码如下:

I am trying to protect my workbook but leave a few cells unprotected for user inputs. The code I am trying is as follows:

Private Sub Workbook_Open()

ActiveWorkbook.Sheets("User Inputs").Range("D6:D12").Locked = False

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
    ws.Protect Password = Password
Next ws

End Sub

当我运行这个时,我收到一个错误,说它无法设置范围类的锁定属性.我怎样才能解决这个问题?此外,当我尝试手动设置密码然后尝试使用宏取消保护时,即使我已输入密码,它也会显示密码不正确.你知道为什么会这样吗?

When I run this, I get an error that says it is unable to set the locked property of the range class. How can I fix this? Also, when I try to set a password manually and then try to unprotect with a macro, it says the password is incorrect, even if I have entered it. Do you know why this might be?

谢谢!我非常感谢您的帮助!

Thanks! I really appreciate any help!

推荐答案

当您按名称明确给出参数时,您应该使用 := 运算符:

When you are explicitly giving the parameter by name, you should use the := operator:

Private Sub Workbook_Open()

    ActiveWorkbook.Sheets("User Inputs").Range("D6:D12").Locked = False

    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
         ws.Protect Password := "SomePassword"
    Next ws

End Sub

或者,只需编写 ws.Protect "SomePassword".

这篇关于保护除少数单元格之外的工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆