Page 1 of 1

Password Protection

Posted: Tue Dec 18, 2007 4:08 am
by jenteh
Hi, I am new here. I have started using OO recently. I have used the macro recording to record the following macro and added the password statement (highlighted in red) , but it doesn't work!

Can anyone please help me? Millions thanks!

rem ----------------------------------------------------------------------
dim args5(4) as new com.sun.star.beans.PropertyValue
args5(0).Name = "Protection.Locked"
args5(0).Value = true
args5(1).Name = "Protection.FormulasHidden"
args5(1).Value = false
args5(2).Name = "Protection.Hidden"
args5(2).Value = false
args5(3).Name = "Protection.HiddenInPrintout"
args5(3).Value = false
args5(4).Name = "Password"
args5(4).Value = "1234"

dispatcher.executeDispatch(document, ".uno:Protection", "", 0, args5())

Re: Password Protection

Posted: Fri Dec 21, 2007 8:31 am
by uros
Hi Jennifer!
Macro recorder seldom gives usefull code.
Two things can be password protected, I'm not quite sure what you need.

Code: Select all

Sub StoreWithPassword
	Dim mProperties(0) As New com.sun.star.beans.PropertyValue
	mProperties(0).Name = "Password"
	mProperties(0).Value = "1234"
	sUrl = convertToURL("file:///home//user/mydocs/document.sxc")
	oDocument = ThisComponent
	oDocument.storeToURL(sUrl,mProperties())
End Sub

Sub PasswordProtectedSheet
	sPass = "1234"
	oDocument = ThisComponent
	oSheets = oDocument.Sheets
	oSheet = oSheets.getByIndex(0)	' first sheet
	oSheet.Protect(sPass)
'	oSheet.Unprotect(sPass)
End Sub
Of course both macros can be combined if you want...
Hope it helps!
Uros

Re: Password Protection

Posted: Fri Dec 21, 2007 12:02 pm
by jenteh
Hi Uros

Thank you so much! Yes, it works perfectly! BTW, what is the difference between StoreWithPassword and PasswordProtectedSheet? PasswordProtectedSheet is the one I am looking for.

Thanks! Have a great weekend!

Re: Password Protection

Posted: Sun Dec 23, 2007 8:33 pm
by uros
Hi Jennifer!
jenteh wrote:BTW, what is the difference between StoreWithPassword and PasswordProtectedSheet? PasswordProtectedSheet is the one I am looking for.
You already know what PPS macro do. SWP macro stores your document as password protected. So next time you try to open this document, you will be asked for a password before actual opening the file...
I'm glad I can help! 8-)
Uros

Re: Password Protection

Posted: Mon Dec 24, 2007 4:03 am
by jenteh
Oh, I see, SWP is password for saving file.

Thanks alot, Uros! I wish you & everyone in this forum a Merry Christmas & a Happy New Year 2008!