PDA

View Full Version : How to Protect a workbook with different encryption in VBA



MaayanSV
03-26-2010, 07:45 AM
Hi,

How to Protect a workbook with different encryption methods in VBA.
:help

With Regards,
maayan

MaayanSV
03-27-2010, 05:26 AM
i found a way to set password with different encryption method in VBA.


ThisWorkbook.SetPasswordEncryptionOptions PasswordEncryptionProvider:= _
"Microsoft Enhanced Cryptographic Provider v1.0", PasswordEncryptionAlgorithm:= _
"RC4", PasswordEncryptionKeyLength:=128, PasswordEncryptionFileProperties:=True
ThisWorkbook.Password="XXXX"


but i got struck when supplying the password while opening the workbook through VBA.

It will be helpful if i get a solution. :help

With Regards,
maayan

mdmackillop
03-27-2010, 07:34 AM
Try

Sub TestOpen()
Workbooks.Open ("C:\Users\Malcolm\Documents\pw.xlsm"), Password:="XXXX"
End Sub

MaayanSV
03-27-2010, 09:39 AM
thanks mdmackillop,

it is working good if i execute it from a different file. but it fails when i keep this procedure in the open event procedure of the same file.

why i ask this is we work in Ms Office and Open Office both , i wanted to restrict this file not be opened through Open Office.

:help

mdmackillop
03-27-2010, 11:21 AM
You cannot run password code from an open event, as the book has not opened.

SamT
03-27-2010, 02:15 PM
You've been here before.
http://www.vbaexpress.com/forum/showthread.php?t=31169

I did some research for you and there is a bug in OO that might work for you.

Insert a sheet in your workbook. Randomly lock some of its Cells. Password protect just that sheet. Save the book and try opening it in OO.

MaayanSV
03-28-2010, 11:35 PM
Thank you all guys.