使用枢轴应用过滤器,并在文件上添加行,并用宏锁定床单

发布于 2025-02-13 11:48:21 字数 1468 浏览 2 评论 0原文

我一次使用以下宏(1和2)锁定并解锁文件:

我想修改这些宏来

  • 过滤表
  • 使用枢轴表
  • 添加行添加线,

我想组合宏1和2 3.

宏1和2在线发现,并记录了宏3。

宏1和2

Sub ProtectAllWorksheets()

    Application.ScreenUpdating = False

    Dim ws As Worksheet
    Dim Pwd As String
    Pwd = InputBox("Enter your password to protect all worksheets", "Protect Worksheets")
    For Each ws In ActiveWorkbook.Worksheets
        ws.Protect Password:=Pwd
    Next ws
    Application.ScreenUpdating = True

End Sub

Sub UnProtectAllWorksheets()

    Application.ScreenUpdating = False

    Dim ws As Worksheet
    Dim Pwd As String
    Pwd = InputBox("Enter your password to unprotect all worksheets", "Unprotect Worksheets")
    On Error Resume Next
    For Each ws In Worksheets
        ws.Unprotect Password:=Pwd
    Next ws
    If Err <> 0 Then
        MsgBox "You have entered an incorect password. All worksheets could not " & _
          "be unprotected.", vbCritical, "Incorect Password"
    End If
    On Error GoTo 0
    Application.ScreenUpdating = True
    
End Sub

宏3

Sub lock1sheetWFilter()
    ' lock1sheetWFilter Macro
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
      , AllowInsertingRows:=True, AllowFiltering:=True, AllowUsingPivotTables:= _
      True

I lock and unlock a file in one time using the below macros (1 and 2):

I would like to amend these macros to

  • filter tables
  • use pivot tables
  • add lines to table

I want to combine macros 1 and 2 to integrate the specifics of macro 3.

Macros 1 and 2 were found online and macro 3 was recorded.

macros 1 and 2

Sub ProtectAllWorksheets()

    Application.ScreenUpdating = False

    Dim ws As Worksheet
    Dim Pwd As String
    Pwd = InputBox("Enter your password to protect all worksheets", "Protect Worksheets")
    For Each ws In ActiveWorkbook.Worksheets
        ws.Protect Password:=Pwd
    Next ws
    Application.ScreenUpdating = True

End Sub

Sub UnProtectAllWorksheets()

    Application.ScreenUpdating = False

    Dim ws As Worksheet
    Dim Pwd As String
    Pwd = InputBox("Enter your password to unprotect all worksheets", "Unprotect Worksheets")
    On Error Resume Next
    For Each ws In Worksheets
        ws.Unprotect Password:=Pwd
    Next ws
    If Err <> 0 Then
        MsgBox "You have entered an incorect password. All worksheets could not " & _
          "be unprotected.", vbCritical, "Incorect Password"
    End If
    On Error GoTo 0
    Application.ScreenUpdating = True
    
End Sub

Macro 3

Sub lock1sheetWFilter()
    ' lock1sheetWFilter Macro
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
      , AllowInsertingRows:=True, AllowFiltering:=True, AllowUsingPivotTables:= _
      True

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

絕版丫頭 2025-02-20 11:48:21

找到了我自己的答案:
我们只需要将宏1的代码修改为以下

Option Explicit

Sub ProtectAllWorksheets()

Application.ScreenUpdating = False

    Dim ws As Worksheet
    Dim Pwd As String
    Pwd = InputBox("Enter your password to protect all worksheets", "Protect Worksheets")
    For Each ws In ActiveWorkbook.Worksheets
        ws.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
           , AllowInsertingRows:=True, AllowFiltering:=True, AllowUsingPivotTables:= _
            True
    Next ws
Application.ScreenUpdating = True

End Sub

found my own answer:
we just have to modify the code of macro 1 to the following

Option Explicit

Sub ProtectAllWorksheets()

Application.ScreenUpdating = False

    Dim ws As Worksheet
    Dim Pwd As String
    Pwd = InputBox("Enter your password to protect all worksheets", "Protect Worksheets")
    For Each ws In ActiveWorkbook.Worksheets
        ws.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
           , AllowInsertingRows:=True, AllowFiltering:=True, AllowUsingPivotTables:= _
            True
    Next ws
Application.ScreenUpdating = True

End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文