|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
请教下大神,这是关于解锁工程密码的一段代码放在 thisworkbook里的
然后,在模块1,“call thisworkbook.解锁工程",
第一次打开执行的时候总是会出现如图所示的错误,但是第二次执行又可以正常
请问下,是哪里出了问题呢
还请指教,谢谢!
Sub 解锁工程()
Dim strPassWord As String
Dim Obj, oWShell
Dim sValue As String
Dim sKey As String
Dim sVersion As String
On Error Resume Next
Set Obj = Application.VBE.ActiveVBProject ' 检查是否勾选VBA工程访问权限
If Err.Number <> 0 Then
Set oWShell = CreateObject("WScript.Shell")
sVersion = Excel.Application.Version
sKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\" & sVersion & "\Excel\Security\" '键的名称
sValue = "AccessVBOM" '信任对vba工程对象模型的访问
With oWShell
.RegWrite sKey & "\" & sValue, 1, "REG_DWORD" '开启对vba工程对象模型的访问,关闭时 1 改成 0
End With
With Application
.SendKeys "~"
.CommandBars.FindControl(ID:=3627).Execute
End With
End If
If Application.VBE.MainWindow.Visible Then Application.VBE.MainWindow.Visible = False
strPassWord = "123"
If ActiveWorkbook.VBProject.Protection = vbext_pp_locked Then
Application.VBE.CommandBars.FindControl(ID:=2578).Execute
SendKeys strPassWord & "{ENTER}{TAB}{ENTER}"
DoEvents
End If
End Sub
|
|