要求是使用Excel加载项保护带有密码的工作簿的VBA项目。使用Excel加载项保护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。