【发布时间】:2025-12-17 20:55:01
【问题描述】:
要求是使用 Excel-Add-in 以密码保护工作簿的 VBA 项目。
这可能吗?
目前我们有一个 Excel 插件 (xlam),它对打开的每个工作簿执行所有操作。 我们通过插件实现了工作表的锁定。 现在我们还想保护那些打开的工作簿的 VBA。下面是我们从各个论坛找到的代码
With Application
'execute the controls to lock the project
.VBE.CommandBars("Menu Bar").Controls("Tools") _
.Controls("VBAProject Properties...").Execute
'activate protection
.SendKeys "^{TAB}"
'CAUTION: this either checks OR UNchecks the
'Lock Project for Viewing checkbox, if it's already
'been locked for viewing, then this will UNlock it\
.SendKeys "{ }"
'enter password
.SendKeys "{TAB}" & VBAProjectPassword
'confirm password
.SendKeys "{TAB}" & VBAProjectPassword
'scroll down to OK key
.SendKeys "{TAB}"
'click OK key
.SendKeys "{ENTER}"
'the project is now locked - this takes effect
'the very next time the book's opened...
End With
但此代码的问题是它保护加载项本身的 VBA 而不是工作簿。我们需要一些代码或解决方法来通过将在 Excel 插件中编写的代码来保护工作簿的 VBA。
【问题讨论】:
标签: vba excel excel-addins vbe