Password Protection

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
jenteh
Posts: 12
Joined: Tue Dec 18, 2007 3:46 am
Location: Malaysia

Password Protection

Post 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())
Jennifer
User avatar
uros
Volunteer
Posts: 30
Joined: Sun Dec 02, 2007 10:26 pm
Location: Slovenia

Re: Password Protection

Post 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
jenteh
Posts: 12
Joined: Tue Dec 18, 2007 3:46 am
Location: Malaysia

Re: Password Protection

Post 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!
Jennifer
User avatar
uros
Volunteer
Posts: 30
Joined: Sun Dec 02, 2007 10:26 pm
Location: Slovenia

Re: Password Protection

Post 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
jenteh
Posts: 12
Joined: Tue Dec 18, 2007 3:46 am
Location: Malaysia

Re: Password Protection

Post 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!
Jennifer
Post Reply