excel取消工作表保护_取消保护所有Excel工作表

excel取消工作表保护

When I'm working on an Excel file for a client, it's nice to have a quick way to unprotect all the worksheets, so I can make changes. It's easy to unprotect the sheets with a macro, like this one.

当我为客户端处理Excel文件时,很高兴有一种快速的方法来取消保护所有工作表,因此我可以进行更改。 像这样一个宏很容易取消保护工作表。

Sub UnprotectAllSheets()
Dim ws As Worksheet
 For Each ws In ThisWorkbook.Worksheets
   ws.Unprotect Password:="MyPassword"
 Next ws
End Sub

It's even easier to run that code to unprotect the sheets, if I add a shortcut for the macro, like Ctrl + Shift + U

如果我为宏添加快捷方式(例如Ctrl + Shift + U),则运行该代码以保护工作表更加容易。

UnprotectAllSheets01

However, I don't want to make it too easy to unprotect the sheets, or the users might do it accidentally. (I'm not going to worry about the few people who are determined to unprotect the sheets – that's a different problem!)

但是,我不想太容易取消保护床单,否则用户可能会意外地这样做。 (我不会为确定要保护床单的少数人担心,这是一个不同的问题!)

在取消保护宏中询问密码 (Ask for Password in the Unprotect Macro)

To help prevent users from accidentally running the macro, I add a few lines to the macro, to prompt for a password. When the macro starts, it prompts you for a password. If you enter the correct password, the sheets are unprotected.

为了防止用户意外运行宏,我在宏中添加了几行以提示输入密码。 宏启动时,会提示您输入密码。 如果输入正确的密码,则表未受到保护。

Sub UnprotectAllSheets()
Dim ws As Worksheet
Dim strPwd As String
Dim strCheck As String
strCheck = "MyPassword"
strPwd = InputBox("Enter Password", "Password", "Enter Password")
If strPwd = strCheck Then
  For Each ws In ThisWorkbook.Worksheets
    ws.Unprotect Password:=strPwd
  Next ws
Else
  MsgBox "Incorrect Password"
End If
End Sub

保护VBA代码 (Protect the VBA Code)

In the UnprotectAllSheets macro, the password, "MyPassword", is shown. Anyone who peeks at the code could easily see that password, and use it to unprotect the sheets.

在UnprotectAllSheets宏中,显示密码“ MyPassword”。 偷看该代码的任何人都可以轻松地看到该密码,并用它来保护工作表。

To help keep the password hidden, you can protect the VBA Project. In the Visual Basic Editor, click the Tools menu, and click VBAProject properties. (If you have named your project, you'll see its name, instead of VBAProject.)

为了帮助隐藏密码,您可以保护VBA项目。 在Visual Basic编辑器中,单击“工具”菜单,然后单击“ VBAProject属性”。 (如果已命名项目,则将看到其名称,而不是VBAProject。)

VBAProtect01

On the Protection tab,

在保护选项卡上,

  1. add a check mark to Lock Project for Viewing,

    在“锁定项目以供查看”中添加复选标记,
  2. enter and confirm a password,

    输入并确认密码,
  3. then click OK.

    然后单击确定。
VBAProtect02

And remember what the password is, so you'll be able to open the project later! _____________

记住密码是什么,以便以后可以打开项目! ______________

翻译自: https://contexturesblog.com/archives/2011/08/24/unprotect-all-excel-sheets/

excel取消工作表保护

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值