PDA

View Full Version : Solved: HOWTO Remove Editing Document Parts (Exceptions) from a Protected Document?



thygizmo
11-09-2008, 03:59 AM
Hi,

I can protect an entire Word document using:

ActiveDocument.Protect Password:="mypassword", NoReset:=False, Type:=wdAllowReadOnly

I can also set exceptions (certain document areas - Ranges - for which I allow editing) using:

Range.Editors.Add WdEditorEveryone

But whenever I unprotect the document with:

ActiveDocument.Unprotect "password"

Those previously document sections, for which I have created exeptions (for allowing editing), are not removed...

Is there a way to remove to Unprotect the document and also remove all previously defined exceptions (areas which are editable???)

Many thanks,

Gizmo

fumei
11-09-2008, 08:49 AM
As this looks like Word 2007 - and BTW, you should mention application version when you post - I can not help you.

However, as Range.Editors appears to allow you to define ranges, it would be there. Use the defined ranges....and delete them.

Although this seems a little odd to me. Why would you unprotect and delete the areas you just had editable?

thygizmo
11-09-2008, 10:34 AM
As this looks like Word 2007 - and BTW, you should mention application version when you post - I can not help you.

However, as Range.Editors appears to allow you to define ranges, it would be there. Use the defined ranges....and delete them.

Although this seems a little odd to me. Why would you unprotect and delete the areas you just had editable?
Hi! Thanks for your reply (I am in fact using MS Word 2007! - sorry).

Well, I want to allow my users to create, update and delete areas (Enclosed Bookmarks) through custom made macros.

These special "sections" are locked against user editing! However, I want to allow my macro do delete these "enclosed bookmarks". Once deleted, I want to allow users to place new "Enclosed Bookmarks" again on any location of the document (which will be filled with external data - and locked again automatically).

Therefore, from within my Macro I need to not only unprotect the document, but also remove all editable exceptions before inserting new "Enclosed Bookmarks", otherwise when the macro inserts new enclosed bookmarks (and sets content inside), I cannot lock the content inside the Enclosed Bookmark anymore, as it has been set as Editable "Exception" previously.

However, I can do it through the "Protect/Unprotect" Task Pane (see "2. Editing Restrictions") - See attached picture (I couldn't post the image directly, as I dont' meet the defined minimum number of posts in this forum..:) )

So, I can define all the regions inside the document (except the Enclosed bookmarks content) and set them as "Editable" to everyone and then I can protect the document.

But how can I undo this? I can unprotect the document, but cannot undo the "editable" exceptions (e.g. remove them)...

Many thanks again!

Gizmo

lucas
11-09-2008, 02:29 PM
Gerry will probably scorch me for this but I would do away with the formfields......if that is what you are using.

I would use a userform and you can unprotect the document and allow data input or edit and then re-protect the document.

ps. I don't have 2007 either so I may be out of school on this.

thygizmo
11-09-2008, 02:45 PM
Hi Lucas,

No, actually I'm not using formfields, just enclosed bookmarks which I lock against editing. Of course then I have to set all the remaining content of the document as an exception to being protected (thus writtable by users).

The problem is that I can do this programatically with VBA but afterwards, I don't know how to undo it...

Any suggestions?

Many thanks,

Gizmo

lucas
11-09-2008, 02:53 PM
I don't have 2007 so I'm not going to be much help but this:

I can also set exceptions (certain document areas - Ranges - for which I allow editing) using:

Range.Editors.Add WdEditorEveryone

seems to be a clue. You can add the exceptions so..in the vbe type:

Range.Editors



then put a period after Editors and intellisense should give you some options.......just a guess.

thygizmo
11-10-2008, 01:47 AM
[quote=lucas]I don't have 2007 so I'm not going to be much help but this:


seems to be a clue. You can add the exceptions so..in the vbe type:

Range.Editors


then put a period after Editors and intellisense should give you some options.......just a guess.[/quote

It's true, that was the first thing I did :) But it seems that there's only one mechanism to created "editable" exceptions in the protected document, but not way to remove them (see attached: range.editors.png).

Also, going to associated Help content, does not help a lot (see attached: range.editors_help.PNG).

Maybe it has to be done through a different command, not available through the Range keyword?

Thank you again for your thoughts!

Gizmo

fumei
11-10-2008, 12:36 PM
Again, as I do not have - not will I ever - Word 2007, i can not give specifics.

However, it is very possible (knowing the basic model structure of VBA), that there are methods available IF you fully qualify the object. Range.Editors has (according to your image), an Item property. You probably have to use it in order to get at further properties and methods.

In other words, IntelliSense may give you more if you use an explicit Index for Item:


Range.Editors.Item(1).some other methods/properties



Perhaps even (but I do not know):
Ranges.Editors.Item(1).Range.Delete

However, I don't know. Editors appears to be a listing of users, but MUST have (somewhere) a property of what the specified range actually is.

thygizmo
11-11-2008, 02:24 AM
Again, as I do not have - not will I ever - Word 2007, i can not give specifics.

However, it is very possible (knowing the basic model structure of VBA), that there are methods available IF you fully qualify the object. Range.Editors has (according to your image), an Item property. You probably have to use it in order to get at further properties and methods.

In other words, IntelliSense may give you more if you use an explicit Index for Item:


Range.Editors.Item(1).some other methods/properties



Perhaps even (but I do not know):
Ranges.Editors.Item(1).Range.Delete

However, I don't know. Editors appears to be a listing of users, but MUST have (somewhere) a property of what the specified range actually is.
Hi, thanks again for the effort in trying to help.

With your help, I have managed to find the solution!!! Here it is:


ActiveDocument.Unprotect Configuration.PROTECT_PASSWORD

Dim objEditor As Editor
Set objEditor = Selection.Editors(1)
objEditor.DeleteAll


Many thanks again,

Gizmo