发布网友 发布时间:2022-04-22 00:41
共3个回答
热心网友 时间:2023-11-28 20:39
'撤销所有保护代码:
Sub UnProtectAll()
Dim sht As Worksheet
myNum = Application.InputBox("请输入密码:", "撤销所有保护")
If myNum = "123" Then
For Each sht In Worksheets
sht.Unprotect Password:="123"
Next
Else
MsgBox "密码错误!"
End If
End Sub
热心网友 时间:2023-11-28 20:39
呃,这样的话,只能通过窗体来过渡了。追问你好,我现在就是做了两个窗体来承载上面两个宏,问题是,第一个还可以,第二个就不行了,因为取消保护时不需要输入密码就能取消了,所以您能否帮我修改下代码?追答呃,你说的应该是模块吧……
在窗体上画一个文字框
然后在画一个按钮
双击按钮
Private Sub CommandButton1_Click()
dim mima as string
Dim sht As Worksheet
mima="123"
if textbox1.text=mima then
For Each sht In Worksheets
sht.Unprotect Password:="123"
Next
else
msgbox "密码错误"
end if
End Sub
或者
Sub UnProtectAll()
Dim sht As Worksheet,mima as string,inmima
mima="123"
inmima= inputbox("密码:")
if inmima=mima then
For Each sht In Worksheets
sht.Unprotect Password:=mima
Next
else
msgbox "密码错误"
end if
End Sub
热心网友 时间:2023-11-28 20:40
Sub UnProtectAll()追问如果把那个PASSWORD 去掉的话,就要每个工作表都输入一次密码来解锁啦,那么这样的话用宏就没意义了,我想要的效果是,只输入一次密码,就能解开所有工作表的密码~~嘻嘻
追答Sub UnProtectAll()
Dim sht As Worksheet
Dim sPwd As String
Dim bln As Boolean
On Error GoTo MyErr
bln = False
sPwd = InputBox("请输入密码!")
For Each sht In Worksheets
sht.Unprotect Password:=sPwd
GoTo MySuccess
MyErr:
bln = True
MySuccess:
If bln Then
MsgBox "密码错误!"
Call ProtectAll
exit sub
End If
Next
End Sub
Sub ProtectAll()
Dim sht As Worksheet
For Each sht In Worksheets
sht.Protect Password:="123"
Next
End Sub