The requirement is to protect the VBA Project of an workbook with password using Excel-Add-in.
Is this possible?
Currently we have an Excel Add-in (xlam) which does all the operation on each of the workbooks opened. We achieved locking of worksheets via Add-in. Now we also want to protect the VBA of those opened workbooks. Below is the code which we found from various forums
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
But issue with this code is it protects the VBA of Add-in itself rather than workbook. We need some code or workaround to protect the VBA of workbook via code which will be written in Excel add-in.