要求是使用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。