PDA

View Full Version : How to enter prompted password



Emperor
12-08-2009, 05:52 AM
Hey all,

For my work I am creating an userform. It is a document wich merges different documents pending what boxes are selected.

The documents inserted may not be edited by the people at the company. This is why is want to password protect opening the files. My question is, how can I insert password protected files and enter the prompted password automatically.

My code (partial)
'Loading needed documents
Selection.GoTo What:=wdGoToBookmark, Name:="specifiek"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
ChangeFileOpenDirectory ".\docs\"

If TextBox3.Value = 101 Then
Selection.InsertFile FileName:="101.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
End If

Thnx in advance!

Mathijs

fumei
12-08-2009, 11:43 AM
1. "The documents inserted may not be edited by the people at the company. "

Once they are inserted, yes they can be edited by the user. Unless they are protected for forms. protected for opening will not be applicable once you insert the file. The files are inserted as text - i.e. the contents. The opening protection is not retained for the contents inserted, as they ARE inserted. Again, once inserted, they are just text, they will not be "opened", thus protection doers not apply.

2. "My question is, how can I insert password protected files and enter the prompted password automatically."

Natively, you can not. Unlike Protection for forms passwords, Open passwords can not be used via code.

3. Why are you using ChangeFileOpenDirectory?

Emperor
12-08-2009, 12:05 PM
The document itself what i am creating isn't possible for the user to enter, the document closes itself after being printed as pdf. The document which need to be imported also need to be protected from opening and editing.

As you know, people always want to go were they are forbidden. My job to stop them in this mater.

How is it possible to secure document from opening and still import them into mine? Or is it not?

Changefiledirectory was in an example i used, I thought I needed it for pointing it to the correct path, because several document are stored in the same folder. Alternatives are always welcome ;-)

fumei
12-08-2009, 01:35 PM
"The document itself what i am creating isn't possible for the user to enter"

How? Do you have it protected for forms?

"The document which need to be imported also need to be protected from opening and editing. "

If these are protected from opening, then the user can not (unless they have the password) open them.

You need to understand the difference between using a password to prevent opening, and using a password to prevent editing. They are different.

If a document is password protected from opening, if it IS opened, this does nothing to prevent editing.

To prevent editing, use protection for forms.

"How is it possible to secure document from opening and still import them into mine? Or is it not?"

They can be imported but you must manually enter the password, if the document file is protected for opening.

Regarding ChangeFileOpenDirectory, you can do it that way, but I rarely ever do this. Also if you DO change it, it is good procedure to change it back when you are done.

Depending on what you are actually doing, you could use the Dir function. This can process any number of files in a folder.

Emperor
12-08-2009, 02:58 PM
Maybe some more information will help explaining what i am creating.

I am making a userform in which users can select different files who will be added to the main document. In this way the document is specific to the needs of the user.
Because the userforms opens when you enter the file, and the userform closes the file when hitting cancel of "Oke and print to PDF" the document is prevented from editing by anyone. ( I also disabled the [X] button )

The files which will be added by selecting the boxes also need to be prevented from use by anyone. It is just formatted text, nothing fancy as in forms. Form protection can be turned on ofcourse, but is not password protected?

The goal is to make sure none of the document, main, inserted or finall is editable. (the possibility to copy text as in a read-only protection is not enough, security needs to be tight)

Thnx for all the trouble till now ;-)

Mathijs

lucas
12-08-2009, 03:16 PM
You seem to be creating and manipulating documents in an application designed to edit documents and that seems to be causing you problems.

Maybe if your need for security is that serious you should consider coding in .NET or something like that where you don't have to create documents to print to pdf. You can just do it within the program.

Just my 2¢

geekgirlau
12-08-2009, 05:14 PM
You could also use AutoText rather than separate documents if you want to keep it in Word. This would mean you only have to worry about protecting 1 document rather than multiples.

However Steve is absolutely correct - you cannot lock down Word and make it 100% secure, you can only secure it from the majority of users. Anyone determined enough or with the right tools will be able to break any security you add.

Emperor
12-09-2009, 12:10 AM
First of all, thank you for all of your time.

Second, I realise that users with a higher knowledge of Word/hacking etc allways will be able to crack the documents.

@ Geekfirlau, i thought for autotext is was not possible to enter formatted text? And only a few sentences? I am linking to files with 7 pages which has been fully formatted with headings etc. My content list uses this headings to fullfill itself in VBA.

My knowledge of .net is nill so for my that is no solution, i've learned VBA for this document so that itself was work enough ^^

Are there other possibilities/commands to insert text into the main document? As I understand it is not possible to password protect the inserted files. (unless I give the password to the users, in which case the use of the password vanishes...)

I am open for ideas :-)

Mathijs

Edit: Is it possible to pasword protect the Form protection for the inserted files? This way they can be imported and are protected?

TonyJollans
12-09-2009, 02:53 AM
I don't entirely follow what you are doing but ...

You can not stop people hacking around and it is not worth the effort to try. Also, your users can see the document content, so your security is not designed to prevent access, rather to prevent updating. Given this, what about a slightly different approach? If you put your documents on a network drive which your users don't have permission to update, would that not solve most of your issues.

Lastly, as geekgirlau said, AutoTexts may be worth looking at, and can be as big as you want and fully formatted.

Emperor
12-09-2009, 04:12 AM
After a little research I now know how to make the autotexts, this will solve my problem :-) (at least enough)

Thank you all.

fumei
12-09-2009, 10:30 AM
I would agree with Tony. It sounds like you want a security level than is more in keeping with Permissions - i.e. access is controlled at the operating system level, not Word.

Word is not secure.

"Edit: Is it possible to pasword protect the Form protection for the inserted files? This way they can be imported and are protected?"

You could easily, within the code for the commandbutton, insert the files, and protect for forms that inserted text. This means the users can not edit.

If the original files are properly controlled by OS Permissions (as Read-Only), the user can not change them.

Emperor
12-10-2009, 12:13 AM
You are right about the permissions, but I try to do something else..
With form protection it is not possible to even copy the text, and thats just it ;-)
The documents are legal documents, the employees may not copy the text to another document and then edit it, a read-only therefor is not enough to secure this.

By not using different documents but using autotext this problem doesnt excists anymore. (because there are no other documents)

As usual (I think ^^) my userform automatically starts with opening the .dot file as it is in initialize. But if in explorer you click with right-mousebutton on the .dot and click open it opens the document without the Userform.
Is there a place to initialize the userform so it will popup when opening as described above?

Mathijs

fumei
12-10-2009, 11:40 AM
"As usual (I think ^^) my userform automatically starts with opening the .dot file as it is in initialize."

I think you mean Document_New. There is no Initialize event for a .DOT file.

"But if in explorer you click with right-mousebutton on the .dot and click open it opens the document without the Userform.
Is there a place to initialize the userform so it will popup when opening as described above?"

The first part is correct. In Explorer, if you right-click and select Open, the the .DOT file itself is opened...not used. Thus the Document_New event - which fires when the .DOT file is used - does NOT fire; thus the userform does not .Show.

1. a user should NEVER be opening a .DOT file itself. Why are they going to Explorer and doing this?

2. No, if they do go through Explorer and right-click the .DOT file itself, then that file is opened, not used. You could however put the userform.Show instruction in the .DOT file Document_Open event, which would show the userform if the .DOT itself is opened. But again, users should not be doing this.