VBA代码,给VBA添加工程密码
- Sub AddVBProjectProtection()
- On Error Resume Next
- Set Obj = Application.VBE.ActiveVBProject ' 检查是否勾选VBA工程访问权限
- If Err.Number <> 0 Then MsgBox " 请勾选信任对VBA工程对象模型的访问": Exit Sub
- If Application.VBE.MainWindow.Visible Then Application.VBE.MainWindow.Visible = False
- Dim pw As Long
- pw = "123"
- Application.VBE.CommandBars(1).Controls("工具(T)").Controls("VBAProject 属性(&E)...").Execute
- Application.SendKeys "^{TAB}" '切换到密码页
- Application.SendKeys "{107}" '勾选查看工程密码
- Application.SendKeys "{TAB}" '换到输入密码
- Application.SendKeys pw '输入密码
- Application.SendKeys "{TAB}" '跳到下一个
- Application.SendKeys pw '输入密码
- Application.SendKeys "{ENTER}" '确定
- End Sub
复制代码
小键盘按键对应代码 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | * | + | | - | {96} | {97} | {98} | {99} | {100} | {101} | {102} | {103} | {104} | {105} | {106} | {107} | {108} | {109} |
键盘按键对应代码
还可以指定键加 shift 键或 ctrl 键 ALT。若要指定键与其他键或键组合,请使用下表。
|