I would like to point out a wee technical issue with explicit values.
The code
Code:
Dim OriginalProtection As WdProtectionType
OriginalProtection = ActiveDocument.ProtectionType
can return OriginalProtection as FOUR possible values.
-1, 0, 1, 2
the code
Code:
If OriginalProtection <> wdNoProtection Then
only tests for ONE value (-1, or wdNoProtection), and then based on that, at the end MAKES ActiveDocument.ProtectionType = 2 (wdAllowOnlyFormFields).
This will work, of course, but it is NOT a good use of explicit logic and values. I know this is fussing, but technically it seeems to me that you should return the document back to its original value...
whatever it was.
If you are only want to test for wdAllowOnlyFormFields, then THAT is what you should test for. This is the use of explicit values.
Code:
If OriginalProtection [b][COLOR=red]= wdAllowOnlyFormFields[/color red][/b] Then
etc etc
Again, I know, I know this is fussing. But say, by accident, someone protected for Comments. And suppose they also added a password to that.
Indulge me here.
Code:
If OriginalProtection <> wdNoProtection Then
[COLOR=red]' this would return TRUE, it is NOT NoProtection[/color red]
ActiveDocument.Unprotect
[COLOR=red]' would fail as no password included.[/color red]
OK, suppose, they did NOT put a password on it. Fine, then the code would roll along, and the document would become unprotected. Cool. Then it gets to the end and the document is protected for forms. The concept was to RE-protect, but in this (admittedly stretched example), it is not RE-protected. It is a new protection, AND not only that, but suppose the original document had different sections? Some protected, some not.
If it WAS originally protected for forms, then protected it again would reinstate the appropriate sections. However, if it was NOT originally protected for forms (back to my accidental protected for Comments), then protecting it for forms would - by default - protect ALL Sections.
Again, I am fussing. I try to have a thing for being explicit.
Test for what you want to (explicitly) test for.
If you are returning things to original states, then return them to what they explicitly were.
No sleep. Ranting......
Gerry
My paintings and sculpture