PDA

View Full Version : MS Word - protection (VBA)



arbeiten100
11-01-2013, 10:55 AM
Hello.

I am from Poland and i am sorry for my mistakes in my statement.

I am writing with request, because i need code in VBA for MS Word and i am begginer. I must protection my document. I would like to:

*lock the print or print only my communique which i will give
*lock copy
*lock button: Print Screen
*lock all buttons on keyboard, when my document is open

Thanks you very much for help.

arbeiten100
11-02-2013, 02:45 AM
Can I count on help?

fumei
11-02-2013, 06:34 PM
1. VBA can not disable Print Screen
2. VBA can not lock the keyboard keys
3. VBA can override a copy with something like:

Sub FileCopy()
Msgbox "Copy is not permitted."
End Sub
4. VBA can override Print with something like:

Sub FilePrint()
Msgbox "Print is disabled."
End Sub

Note that the print override ALSO stops you as well, unless you remove the subroutine (or edit it).
Note that anyone who knows even a little VBA could get around the override.

macropod
11-03-2013, 03:13 AM
Note that anyone who knows even a little VBA could get around the override.
The user doesn't even need to know any vba - all they need to do is to not allow the macros to run. Indeed, if their system security is high enough, the macros will be automatically disabled without the user ever knowing. Alternatively, to get rid of the macros, the user could simply re-save the document in the docx format ... all vba-based protection is gone!

fumei
11-03-2013, 03:01 PM
Shrug...what can I say. I was being - sort of - optimistic for the OP.

But yeah, the request is kind of hopeless.

Aussiebear
11-04-2013, 01:57 AM
@ Paul & Gerry, Is it possible that on opening the document, that it checks the file extension name and if it doesn't match docx, then the file remains invisible to the user

Aussiebear
11-04-2013, 02:12 AM
Actually, just another quick thought, ( at my age quick thoughts is about all I have time for). How about on opening the file, check the file extension and if it doesn't match docx then auto resave file as the name and extension required? Some will say that if macro's are not enabled this won't work... so if macro's are not enabled then do not open this document.

macropod
11-04-2013, 02:33 AM
Is it possible that on opening the document, that it checks the file extension name and if it doesn't match docx, then the file remains invisible to the user
Not really - a docx file can't run a macro, since it can't contain one. The only way such a check could be done, therefore, is via a Document_Open macro in the document's attached template (which the user could change). Even so, regardless of the file format, hiding text is a spectacularly weak form of protection - the user can simply check the 'display hidden text' setting and/or select all the content (eg via Ctrl-A) then format the text as unhidden.

Aussiebear
11-04-2013, 03:47 AM
Someone pour some water on me.... I've been shot down but in the kindest way.

fumei
11-04-2013, 03:25 PM
Splish splash takin' a bath....

Care to elaborate WHY you want to make the file invisible if it is not docx.

Aussiebear
11-04-2013, 08:48 PM
Sure, typo on my behalf. ( and here's your towel) .Docm should have been what I was writing about.

fumei
11-04-2013, 09:57 PM
Yes OK, but WHY do you want to make it invisible?

macropod
11-04-2013, 10:12 PM
More to the point, why have a macro check that the document is in the .docm format? Seems to me the .doc format would be just as valid. However, since a user can re-save the document in the docx format, which wipes out the macro, you're back to square one ...

Aussiebear
11-05-2013, 12:25 AM
@Gerry, if the file is not in the correct format as the original then it has been altered, so prevent any further use of the file

fumei
11-05-2013, 03:07 PM
The file has been altered? Shrug...maybe. But think of this. If someone renamed the fileNAME...but not the file itself, does that count as "altered"? What if they totally changed the contents, but retained the filename AND format...does that mean it is NOT altered.

Sorry, but I do not understand - still - why you want to do a check of file extension name. It does not make any sense to me.

Aussiebear
11-05-2013, 07:39 PM
@ Gerry. Suppose for example I build a document called Data.docm, which I make available to certain other users. Some of the information within the document is sensitive, therefore it needs to be limited as to its availability to others and I need to protect the document from being printed, copied or being altered.

Here is my concept. Set up a macro which calls the document. Before displaying the document, check that macro's are enabled, check that the file is of (1) the correct format ( .docm) so that macro's within the document can be run, and (2) is of the correct file name. If the file name is either not correct or has the wrong extension, then do not make the file visible to the user. You can send a message to the potential user such as "No permission to access file".

a) What happens if the file has been copied? Encrypt the file on closure, so if its copied it becomes useless to anyone other than the intended person/s who call the file to be opened through a separate macro. On opening the file, un-encrypt the file providing that it passes the checks mentioned earlier.

b) What happens if the file is not the correct one? Simply do not display the document or failing that display the encrypted version only

c) If the file is correct, then run the macro's which as the OP asked for as in prevent Print, Copy amd lock all non required keys.

d) This is a lot of effort . True but most normal users aren't that skilled in VBA or getting around simple protection.

Surely with a little bit of thought this can be made to happen.

macropod
11-05-2013, 07:50 PM
Suppose for example I build a document called Data.docm, which I make available to certain other users. Some of the information within the document is sensitive, therefore it needs to be limited as to its availability to others and I need to protect the document from being printed, copied or being altered.

Here is my concept. Set up a macro which calls the document. Before displaying the document, check that macro's are enabled, check that the file is of (1) the correct format ( .docm) so that macro's within the document can be run, and (2) is of the correct file name. If the file name is either not correct or has the wrong extension, then do not make the file visible to the user. You can send a message to the potential user such as "No permission to access file".
Unless (a) the macro is attached to the document template and (b) the users are using the same template, it'll never fly. If they do, it really doesn't matter what the extension is.

Conversely, if you try to embed the macro in the document itself, all the user need do is open it, display the content then save in the docx format. Once they do that, your protection is forever gone, as the .docx file cannot contain the macro needed to implement any of this scheme.

In any event, none of this addresses the OP's concern, which is to prevent editing, copying and printing, not content display. That's all done quite easily with a PDF but not with a Word document.

fumei
11-05-2013, 11:20 PM
Paul got his dibs in before I could post but I will add my own two cents.


a) What happens if the file has been copied? So...IF, while the file is open, someone uses a CTRL-A (copy everything) you are going to set some variable that, when the file is sunsequently closed WITH OR WITHOUT any changes, causes some sort of encryption. Hmmm. Please post how you are going to do that.

But no, you state: Encrypt the file on closure, so if its copied it becomes useless to anyone other than the intended person/s who call the file to be opened through a separate macro. On opening the file, un-encrypt the file providing that it passes the checks mentioned earlier

So, ummm, what do you mean by "if it is copied"? That sounds liked copied after the encryption. Copied how? Copied using a commandline? How does Word know this?


b) What happens if the file is not the correct one? Defined how? And do not state that is is docm.

check that macro's are enabled, check that the file is of (1) the correct format ( .docm) so that macro's within the document can be run

These are the same thing essenitally.


and (2) is of the correct file name.

Again, what makes it "correct", when the content could be changed, deleted entirely...and have the "correct" name. You can name files anything.


c) If the file is correct, then run the macro's which as the OP asked for as in prevent Print, Copy amd lock all non required keys.
As it has been stated, you can not in ANY real way prevent this.


d) This is a lot of effort . True but most normal users aren't that skilled in VBA or getting around simple protection.

Surely with a little bit of thought this can be made to happen. I have seen this sort of request and desire at least three or four times a year for the last fifteen years. Yes, it can be done...sort of. Particularly the things about most normal users. But is it the normal users that are the concern? If not, and (and is it?) the document is THAT important that extraordinary means are required, then those that would want to try and get it...WILL get it.

fumei
11-05-2013, 11:48 PM
Bottom line is that Word documents are not, never have been, never will be, in themselves secure. Heck that is one of the reasons why PDF was invented in the first place. To prevent others changing things. But now of course even THAT is no longer "secure".

Aussiebear
11-06-2013, 01:02 AM
@ Gerry, I'm sorry its so complicated for you

macropod
11-06-2013, 05:01 AM
@ Gerry, I'm sorry its so complicated for you
I don't think Gerry's at fault here. My own impression is that you haven't/hadn't understood the issues.

Aussiebear
11-06-2013, 05:02 AM
Thanks Paul but I'm in no mood for his games

fumei
11-06-2013, 08:11 PM
That sounds vaguely insulting. What do you mean by that? I do not find it complicated whatsoever.

fumei
11-06-2013, 08:16 PM
I will amend that. It is not vaguely insulting at all. There is nothing vague about it. What games? I am not playing ANY games. I am seriously stating my opinion of the situation based on years of experience. I am happy to acknowledge that it IS just my opinion.

Frankly if your mood is affected perhaps you need a vacation. OR...if you have a serious and practical solution, then post it. I am not so senstive to mood that I would not be absolutely delighted to have a serious and practical solution. Your call.