使用枢轴应用过滤器,并在文件上添加行,并用宏锁定床单
我一次使用以下宏(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了我自己的答案:
我们只需要将宏1的代码修改为以下
found my own answer:
we just have to modify the code of macro 1 to the following