View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Programmaticlly sign and password protect a VBA Project in Excel 2

Excel doesn't give developers this feature--if it did, then any workbook's
project could be easily cracked.

If your code is really in the ThisWorkbook module, then I'd create a template
file with that code already in it. And that workbook's project would be
protected.

Then instead of creating a new workbook with:

set newwkbk = workbooks.add(1)
or
worksheets("somesheet").copy 'to a new workbook

I'd use:
set newwkbk = workbooks.add(Template:="C:\yourpath\yourtemplatef ile.xlt")
worksheets("somesheet").copy _
after:=newwkbk.worksheets(1)
application.displayalerts = false
newwkbk.worksheets("DeleteMeLater").delete
application.displayalerts = true

(Yes, DeleteMeLater is a dummy sheet in that template workbook.)



RoccoCoetzee wrote:

Hi

I have a workbook that has a vba project attached which is signed and
password protected.

In this workbook I've created a sub that creates a new workbook (by moving a
worksheet to a new workbook) adds code to its "ThisWorkBook" module
(basically to unprotect, process data and protect the worksheet when a user
makes changes to a specific range).Thus this code contains passwords to
protect and unprotect a worksheet which I don't want any of my users to view
if they open the VBA editor.

I need to be able to programmatically password protect the newly created
workbook's vba project and add the original workbook's signature to it to
enable macro functionality on it.

Could someone please advise on how I go about this as I am baffled.

--
Rocco Coetzee


--

Dave Peterson