一个button来保护所有工作表的密码和一个button来解除保护
我有大约180个工作表的工作簿。
我正在尝试创build2个macros:
1)单击button保护所有工作表
2)单击button解除所有工作表的保护,但要求用户input密码
这里我已经…
Sub Protect() Dim ws As Worksheet Dim pwd As String pwd = "xyz" ' Put your password here For Each ws In Worksheets ws.Protect Password:=pwd, UserInterfaceOnly:=True Next ws End Sub
并取消保护…
Sub UnProtect() Dim ws As Worksheet Dim pwd As String pwd = "xyz" ' Put your password here For Each ws In Worksheets ws.UnProtect Password:=pwd Next ws End Sub
保护macros工作正常。
UnProtectmacros保护所有的工作表,但我需要它来要求用户input密码。
谁能帮忙?
Sub UnProtect() Dim ws As Worksheet Dim pwd As String Dim myValue As Variant pwd = "xyz" ' Put your password here myValue = InputBox("What is the password?") If myValue = pwd Then For Each ws In Worksheets ws.UnProtect Password:=pwd Next ws Else 'do nothing or msgbox End If End Sub