PDA

View Full Version : Solved: Save file with password and allow user to choose where



clhare
02-22-2007, 09:52 AM
Hi all!

Can this be done? I have created a template for a letter. They want to be able to save the file they create using whatever they want for the filename and save it wherever they want...but, they want it to be password protected so that the user cannot change the letter without approval. (So the user can't know what the password is!)

I was thinking I have to use the SaveAs dialog box somehow to get the filename and location from the user, but I don't know the best way to do that. Also, is there a way to make sure the filename doesn't already exist in that location, and if so, tell them to try again?

Then once I'm set on the filename/location, I have to get the password assigned.

:dunno Totally stumped on this one!

lucas
02-22-2007, 10:19 AM
Just put something like this in the thisDocument module of the template......when a new document is created from the template it will be password protected with the password you put in. This one is set up to only allow form fields to be changed on the new document
Private Sub Document_New()
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Password:="password", _
Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub

search help in the vba editor....not regular word for protect for more info.

clhare
02-22-2007, 11:12 AM
Wow! What a simple solution! Thank you!!

lucas
02-22-2007, 11:43 AM
Your welcome...still learning myself.

clhare
02-23-2007, 01:06 PM
Okay, the part about locking the document with a password works great, but if I need to unlock a document that has a password, how do I do that in a macro? I tried the following, but it didn't work:

If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Protect wdNoProtection, Password:="test"
End If

lucas
02-23-2007, 01:30 PM
Try this Cheryl:
Dim strPassword As String
strPassword = "test"
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=strPassword
End If

clhare
02-23-2007, 01:36 PM
Worked perfectly! Thanks!