16,013,548 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by zengfuxu (Top 2 by date)
zengfuxu
23-Feb-12 20:56pm
View
I know how to protect a word document using VB code ActiveDocument.Protect as described in that article. The problem with Word 2010 document is, after protection type of a document changed programmatically, it fails to save so the document still keeps the original protection type when it is closed and reopened. This is a MS confirmed bug in Word 2010.
zengfuxu
22-Feb-12 21:14pm
View
Sorry my question is:
We would like to enforce and remove different types of Document Protection (Restrict Editing) on a whole Word 2010 document in code.
Our code has worked in previous version of Word but is no longer working with the new version. When changing protection type from
wdAllowOnlyRevisions to wdAllowOnlyFormFields, our code is designed to unprotect the document and then protect it with a new
protection type as follows.
ProtectioType = ActiveDocument.ProtectionType
If ProtectioType = wdAllowOnlyRevisions Then
ActiveDocument.Unprotect()
ActiveDocument.Protect(Password:="xxxxx", NoReset:=True, Type:= wdAllowOnlyFormFields, UseIRM:=False, EnforceStyleLock:=False)
End If
After ActiveDocument.Unprotect executed, ActiveDocument.ProtectionType becomes -1 which is correct. But in the document
the Restrict Editing pane (From the document ribbon menu Review -> Restrict Editing) settings are not changed. The
"2. Allow only this type of editing in the document:" checkbox is still checked for "Tacked changes". Therefore,
when code ActiveDocument.Protect is executed, wdAllowOnlyFormFields protection type is not applied and it keeps wdAllowOnlyRevisions.
However, after unprotecting the document in code and before calling the protect method in code,
the "2. Allow only this type of editing in the document:" checkbox is still checked (in the Review->Restrict
Editing panel in the ribbon menu of the document). As the result, the document is not protected as we want it to be when using the code.
Are there any VBA/Word functions we can use to programmatically clear that checkbox in the Restrict Editing panel? Many thanks!