如何使用VBA保护Excel工作簿? [英] How to protect Excel workbook using VBA?

查看:515
本文介绍了如何使用VBA保护Excel工作簿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个类似复选框的触发器,我想保护我的工作簿。我试过Excel 2003:

With a trigger like a check box I want to protect my work book. I tried Excel 2003:

thisworkbook.protect("password",true,true)

thisworkbook.unprotect("password")

它不工作。任何建议?

推荐答案

我同意@Richard Morgan ...你在做什么应该工作,所以更多的信息可能是

I agree with @Richard Morgan ... what you are doing should be working, so more information may be needed.

Microsoft对保护选项的建议您的Excel 2003工作表

Microsoft has some suggestions on options to protect your Excel 2003 worksheets.

这里有一些更多的信息.​​..

Here is a little more info ...

从帮助文件(保护方法):

From help files (Protect Method):

expression.Protect(Password, Structure, Windows)

表达式必需。返回一个Workbook对象的表达式。

expression Required. An expression that returns a Workbook object.

密码可选变体指定工作表或工作簿区分大小写的密码的字符串。如果省略此参数,则可以在不使用密码的情况下取消保护工作表或工作簿。否则,您必须指定密码以取消保护工作表或工作簿。如果您忘记密码,则无法取消保护工作表或工作簿。最好在一个安全的地方保存您的密码和相应文件名称列表。

Password Optional Variant. A string that specifies a case-sensitive password for the worksheet or workbook. If this argument is omitted, you can unprotect the worksheet or workbook without using a password. Otherwise, you must specify the password to unprotect the worksheet or workbook. If you forget the password, you cannot unprotect the worksheet or workbook. It's a good idea to keep a list of your passwords and their corresponding document names in a safe place.

结构可选变体。真实保护工作簿的结构(表格的相对位置)。默认值为False。

Structure Optional Variant. True to protect the structure of the workbook (the relative position of the sheets). The default value is False.

Windows可选变体。为保护工作簿窗口。如果这个参数被省略,窗口就不被保护。

Windows Optional Variant. True to protect the workbook windows. If this argument is omitted, the windows aren’t protected.

ActiveWorkbook.Protect Password:="password", Structure:=True, Windows:=True

如果你想在工作表级别工作,我使用了类似的年代之前当我需要保护/取消保护时:

If you want to work at the worksheet level, I used something similar years ago when I needed to protect/unprotect:

Sub ProtectSheet()
    ActiveSheet.Protect "password", True, True
End Sub

Sub UnProtectSheet()
    ActiveSheet.Unprotect "password"
End Sub

Sub protectAll()
    Dim myCount
    Dim i
    myCount = Application.Sheets.Count
    Sheets(1).Select
    For i = 1 To myCount
        ActiveSheet.Protect "password", true, true
        If i = myCount Then
            End
        End If
        ActiveSheet.Next.Select
    Next i
End Sub

这篇关于如何使用VBA保护Excel工作簿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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