ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1802|回复: 0

[求助] [求助]以下清除活动VBA 工程口令的代码在Excel 2003中无效

[复制链接]

TA的精华主题

TA的得分主题

发表于 2007-5-22 10:52 | 显示全部楼层 |阅读模式
<p>以下清除活动VBA 工程口令的代码在Excel 2003中无效,不知原因</p><p><br/>'need&nbsp; reference To VBA Extensibility<br/>'need To make sure that the target project Is the active project</p><p>Sub test()<br/>'&nbsp;&nbsp;&nbsp; Workbooks.Open ThisWorkbook.Path &amp; "\test1.xls"<br/>&nbsp;&nbsp;&nbsp; UnprotectVBProject Workbooks("test1.xls"), "password"<br/>End Sub</p><p>Sub UnprotectVBProject(WB As Workbook, ByVal Password As String)<br/>'<br/>' Bill Manville, 29-Jan-2000<br/>'<br/>&nbsp;&nbsp;&nbsp; Dim VBP As VBProject, oWin As VBIDE.Window<br/>&nbsp;&nbsp;&nbsp; Dim wbActive As Workbook<br/>&nbsp;&nbsp;&nbsp; Dim i As Integer</p><p>&nbsp;&nbsp;&nbsp; Set VBP = WB.VBProject<br/>&nbsp;&nbsp;&nbsp; Set wbActive = ActiveWorkbook</p><p>&nbsp;&nbsp;&nbsp; If VBP.Protection &lt;&gt; vbext_pp_locked Then Exit Sub</p><p>&nbsp;&nbsp;&nbsp; Application.ScreenUpdating = False</p><p>&nbsp;&nbsp;&nbsp; ' Close any code windows To ensure we hit the right project<br/>&nbsp;&nbsp;&nbsp; For Each oWin In VBP.VBE.Windows<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If InStr(oWin.Caption, "(") &gt; 0 Then oWin.Close<br/>&nbsp;&nbsp;&nbsp; Next oWin</p><p>&nbsp;&nbsp;&nbsp; WB.Activate<br/>&nbsp;&nbsp;&nbsp; ' now use lovely SendKeys To unprotect<br/>&nbsp;&nbsp;&nbsp; Application.OnKey "%{F11}"<br/>&nbsp;&nbsp;&nbsp; SendKeys "%{F11}%TE" &amp; Password &amp; "~~%{F11}", True</p><p>&nbsp;&nbsp;&nbsp; If VBP.Protection = vbext_pp_locked Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' failed - maybe wrong password<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SendKeys "%{F11}%TE", True<br/>&nbsp;&nbsp;&nbsp; End If</p><p>&nbsp;&nbsp;&nbsp; ' leave no evidence of the password<br/>&nbsp;&nbsp;&nbsp; Password = ""<br/>&nbsp;&nbsp;&nbsp; ' go back To the previously active workbook<br/>&nbsp;&nbsp;&nbsp; wbActive.Activate</p><p>End Sub</p><p>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''<br/>Sub ProtectVBProject(WB As Workbook, ByVal Password As String)</p><p>&nbsp;&nbsp;&nbsp; Dim VBP As VBProject, oWin As VBIDE.Window<br/>&nbsp;&nbsp;&nbsp; Dim wbActive As Workbook<br/>&nbsp;&nbsp;&nbsp; Dim i As Integer</p><p>&nbsp;&nbsp;&nbsp; Set VBP = WB.VBProject<br/>&nbsp;&nbsp;&nbsp; Set wbActive = ActiveWorkbook</p><p>&nbsp;&nbsp;&nbsp; ' Close any code windows To ensure we hit the right project<br/>&nbsp;&nbsp;&nbsp; For Each oWin In VBP.VBE.Windows<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If InStr(oWin.Caption, "(") &gt; 0 Then oWin.Close<br/>&nbsp;&nbsp;&nbsp; Next oWin</p><p>&nbsp;&nbsp;&nbsp; WB.Activate<br/>&nbsp;&nbsp;&nbsp; ' now use lovely SendKeys To unprotect<br/>&nbsp;&nbsp;&nbsp; Application.OnKey "%{F11}"<br/>&nbsp;&nbsp;&nbsp; SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" &amp; Password &amp; "{TAB}" &amp; Password &amp; "~"<br/>&nbsp;&nbsp;&nbsp; Application.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute<br/>&nbsp;&nbsp;&nbsp; WB.Save<br/>End Sub<br/>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''<br/></p>
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2025-1-11 19:54 , Processed in 0.015769 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表