Cannot Change Protection With VBA In Word 2007


"Excel VBA Help"

 


Play Friv Now - Play Friv Games
Go Back   The Code Cage Forums > Microsoft Topics > Microsoft Word Forum
Our Info Pages:-
The Code Cage - Microsoft Office help

Notices

Microsoft Word Forum Members, post questions in this forum if they are related to using Microsoft Word, this includes Document Properties, VBA Programming & Functionality etc.

New Reply
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
  #1  
Unread 27th May 2010, 21:44
Trevor's Avatar
Trevor
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default Cannot Change Protection With VBA In Word 2007
     Word: VBA   


With Word 2007, I cannot use VBA to permanently change the type of
protection applied to a document. VBA changes the protection while
the document is opened but once the document is closed the changes are
not written to the OOXML on disk.

Steps to reproduce:

Step 1
Create a new document in Word 2007.

Step 2
From the VBA Immediate Window, execute the following statement.

ActiveDocument.Protect Password:="MyPassword", NoReset:=True,
Type:=wdAllowOnlyComments, UseIRM:=False, EnforceStyleLock:=False

Step 3
Verify that the specified protection has been added to the new
document.

? ActiveDocument.ProtectionType = wdAllowOnlyComments
True

Step 4
Save the document as "Test.docx" to a convenient location (i.e.
Desktop) and close.

Step 5
Inspect the "Test.docx/word/settings.xml" document part using a tool
such as "Open XML SDK 2.0 Productivity Tool for Microsoft Office".
There should be an element like the following.

<w:documentProtection w:edit="comments" w:enforcement="1"
w:cryptProviderType="rsaFull" w:cryptAlgorithmClass="hash"
w:cryptAlgorithmType="typeAny" w:cryptAlgorithmSid="4"
w:cryptSpinCount="100000" w:hash="..." w:salt="..." xmlns:w="http://
schemas.openxmlformats.org/wordprocessingml/2006/main" />

Step 6
Open "Test.docx" in Word 2007 and run the following in the VBA
Immediate Window.

ActiveDocument.Unprotect "MyPassword"
ActiveDocument.Protect Password:="MyPassword", NoReset:=True,
Type:=wdAllowOnlyRevisions, UseIRM:=False, EnforceStyleLock:=False

Step 7
Verify that the protection for "Test.docx" has been changed to the
specified type.
? ActiveDocument.ProtectionType = wdAllowOnlyRevisions
True

Step 8
Close "Test.docx" saving changes.

Step 9
Inspect the "Test.docx/word/settings.xml" document part again using
the same method as step 5. The documentProtection element will appear
unchanged:

<w:documentProtection w:edit="comments" w:enforcement="1"
w:cryptProviderType="rsaFull" w:cryptAlgorithmClass="hash"
w:cryptAlgorithmType="typeAny" w:cryptAlgorithmSid="4"
w:cryptSpinCount="100000" w:hash="..." w:salt="..." xmlns:w="http://
schemas.openxmlformats.org/wordprocessingml/2006/main" />

According to ECMA 376 2nd Ed., after the VBA commands in step 6, it
should be:

<w:documentProtection w:edit="trackedChanges" w:enforcement="1"
w:cryptProviderType="rsaFull" w:cryptAlgorithmClass="hash"
w:cryptAlgorithmType="typeAny" w:cryptAlgorithmSid="4"
w:cryptSpinCount="100000" w:hash="..." w:salt="..." xmlns:w="http://
schemas.openxmlformats.org/wordprocessingml/2006/main" />

There appears to be a disconnection between the Word document object
model in memory and the OOXML written to disk. Can anyone else
reproduce this behavior? If yes, any insights on how to resolve this
will be very much appreciated!

The Code Cage Advertisment
Advertisement
New Reply
The Code Cage at Facebookhe Code Cage at Twitter


Tags
2007, change, protection, vba, word

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

The Code Cage Affilliates



http://www.thecodecage.com/forumz tested by McAfee Security http://www.thecodecage.com/forumz tested by McAfee Security

All times are GMT +1. The time now is 17:12.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Template-Modifications by TMS
No part of this board, functionality or creatives may be copied or reproduced either in part or full without the express permission of The Code Cage Team.
Copyright ©2008 - , Simon lloyd.
We are not associated with nor employed by Microsoft in any way, we simply provide resources!
All MS office icons are registered trademarks of the application they represent and are used with permission from Microsoft
UA-8135493-1
Cultural Forum | Study at Malaysian University