excel - 如何防止从 protected excel表中复制

标签 excel vba

我试图保护我的 excel 中的一些列。我尝试了下面提到的这段代码,但它不起作用任何人都可以帮助我解决这个问题。

Sub ARCProtectPwdRFQ()

ActiveSheet.Unprotect Password:="arc"
Cells.Locked = False

ActiveSheet.Range("A1", "D100").Locked = True
Columns("I:I").EntireColumn.Locked = True
ActiveSheet.Protect Password:="arc", UserInterFaceOnly:=True   'DrawingObjects:=True, Contents:=True, Scenarios:=True

End Sub

最佳答案

这是你正在尝试的吗?

Sub ARCProtectPwdRFQ()
    Dim ws As Worksheet
    
    '~~> Change this to the relevant sheet
    Set ws = Sheet1

    With ws
        .Unprotect Password:="arc"
        .Cells.Locked = False

        .Range("A1", "D100").Locked = True
        .Columns("I:I").EntireColumn.Locked = True

        .Protect Password:="arc", UserInterFaceOnly:=True, _
        DrawingObjects:=True, Contents:=True, Scenarios:=True

        .EnableSelection = xlUnlockedCells
    End With
End Sub
要防止复制,只需使用 .EnableSelection = xlUnlockedCells 禁用锁定单元格的选择即可。 .
还要避免使用 Activesheet除非并且直到绝对必要。使用对象。

关于excel - 如何防止从 protected excel表中复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69304937/

相关文章:

excel - 如何解决 VBA 和 Powershell 之间的这种特殊字符编码问题?

EXCEL VBA : Format text after Point in each Cell

VBA 类型不匹配错误 - 不一致

Excel - VBA - 创建每个主键的唯一代码组合

vba - 运行vb代码计算相似度时定义首字母缩略词

vba - 在 Excel VBA 中插入数组公式

excel - 在 Excel 单元格的最后一个 '.' 之后添加字符串

excel - VBA 中的字符串分隔问题

excel - 过滤后的行地址

mysql - 供远程 Excel 用户使用的数据库