【问题标题】:VBA to protect an Excel sheet but allow sort, autofilter, charts, copyVBA 保护 Excel 工作表,但允许排序、自动筛选、图表、复制
【发布时间】:2013-11-20 10:47:42
【问题描述】:

我的工作簿包含将近 25 张,我想保护 11 张。我的保护标准如下:

1. User cannot delete or modify any cell
2. User should be able to use SORT, AUTOFILTER, drop down selection from COMBO BOXES
3. Most of the sheets contain charts, they should be updated as per the user selection
4. User should not be able to see the formulas in the formula bar
5. User should be able to copy the data

我已经尝试了 Excel 中的所有常规选项,它完成了上述所有工作,但它们使单元格解锁,这意味着用户可以删除内容

因此我希望这只能通过宏来实现,请帮助。

【问题讨论】:

  • 您是否担心删除内容或单元格?
  • @siddharth-rout 是的,我担心有人会不小心删除单元格内容
  • 你看到我发布的答案了吗?

标签: vba excel


【解决方案1】:

我已经尝试了 Excel 中的所有常规选项,它完成了上述所有工作,但它们使单元格保持解锁状态,这意味着用户可以删除内容

由于其他一切都适合您,因此我不会尝试解决这些问题。有了你已经拥有的,将此代码添加到工作表代码区域中

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo Whoa

    Dim rng As Range

    Application.EnableEvents = False

    For Each rng In Target
        If rng.Value = "" Then
            Application.Undo
            Exit For
        End If
    Next
Letscontinue:
    Application.EnableEvents = True
    Exit Sub
Whoa:
    MsgBox Err.Description
    Resume Letscontinue
End Sub

【讨论】:

  • 好的,宏会恢复已删除的单元格,但如果用户修改了单元格,则允许这样做。对不起,如果我不够清楚,这些单元格基本上包含公式,我必须解锁它们才能启用排序/自动过滤器等,这使它们容易受到攻击。能否请您更改代码,以便用户无法修改单元格内容。
猜你喜欢
  • 1970-01-01
  • 2018-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多