Sub 破解密码() '破解密码
Dim strPassWord As String
'关闭VBE主窗口
Application.VBE.MainWindow.Visible = False
strPassWord = "123" '密码字符串
'判断是否设置了工程保护,使用密码打开工程
If ActiveWorkbook.VBProject.Protection = 1 Then
Application.VBE.CommandBars.FindControl(ID:=2578).Execute
SendKeys strPassWord & "{ENTER}{TAB}{ENTER}"
DoEvents '更新工程状态
End If
call 删除代码 ’进入第2步
End Sub
‘第2步
Sub 删除代码() ‘删除非“我的工程”的其他模块
Dim a, b
For Each a In Application.VBE.VBProjects
If a.Name <> "我的工程" Then
For Each b In a.VBComponents
If InStr(b.Name, "模块") > 0 Then
'MsgBox b.Name
a.VBComponents.Remove (b)
End If
Next b
End If
Next a
End Sub