Cannot Change Protection With VBA In Word 2007

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!
0
Trevor
5/27/2010 8:41:01 PM
word.vba.general 1023 articles. 0 followers. Follow

0 Replies
1334 Views

Similar Articles

[PageSpeed] 6

Reply:

Similar Artilces:

External data link change
Hi, I've a sheet linked to an external data on the net, and I would like that a cell in this sheet to indicate the last date and time it was updated, the simplest way the better but I can do some programming too. Thanks for your attention, -- Domingos Junqueira No need of help any more, I solved the question. Thanks again ...

getpivotdata in excel 2007
=+GETPIVOTDATA(pivot1,$A$3 & " " &B$2 & " " &A5) I'm trying to return pivot table data to another sheet. The range of the pivot table is called "pivot1" and the reference cells represent (name of doc), (date), (procedure type). I get a REF# I have spent hours already and need a solution fast. Please Fern wrote: > =+GETPIVOTDATA(pivot1,$A$3 & " " &B$2 & " " &A5) > > I'm trying to return pivot table data to another sheet. The range of the > pivot table is called "pivot1" and...

Why does the change change to a number?
Hi all, I've noticed something wierd and always wondered WHY it happens. When you type a date into a cell, and then change the Formatting of it to a 'general' cell, it turns into a number. How does it come up with that number? What is the significance? i.e. type today's date of "12/7/2007" - change it to a 'General' format, and it then says "39423". I'm a trainer of Excel and this question always comes up. I'm curious myself too. Thanks! Joe It's the number of days since January zero 1900 using Excel default for windows (M...

changing the way Excel displays selected cells
Is there a way to change the way Excel displays selected cells? I'm interested in viewing all the selected cells highlighted (with light blue for instance), but by default excel highlights all the cells but not the first one the same occurs when you define a range with no adyacents cells Your definition of the display is not quite correct. Excel highlights the current cell, Excel also highlights a selecte range. The currently selected cell is generally the first of a range, bu press enter and the current cell changes and becomes the second, the third etc in the range. You cannot...

VBA Help Files #2
Kabel and Dibben - VBA Help files not on my installation CD any further clues as to where I can go on MSFT sites to find and download these files? Will start searching now yet could not find yesterday! TX JHAM Has been a long time since I installed Excel 97 and do not have the CD available. I think I remember that when originally installing the same thing happened to me when I chose the basic install......No VBA help files. Next time around I chose "Custom Install" and the VBA Help files were automatically downloaded and installed from the 'net. If you have the CD try the ...

Track Changes
How do i remove the track changes in outlook? When i press "Enter", a symbol that represents "Enter" will appears. Same for space etc. ...

DST changes for Exchange 5.5
I noticed the 2007 DST Calendar Update "Exchange tool" is available now: http://support.microsoft.com/kb/930879 This will seemingly take care of calendars for mailboxes still on Exchange 5.5 servers, as Exchange 5.5 is listed as "compatible" . However would this address the CDO issues such as BlackBerry users and OWA users still on Exchange 5.5 ? Thanks in advance, Itrcb4 On Mon, 12 Feb 2007 14:31:00 -0800, itrcb4 <itrcb4@discussions.microsoft.com> wrote: >I noticed the 2007 DST Calendar Update "Exchange tool" is available now: > >http://su...

Can't Publish changes with Deploy Manager
After a migration process, I can't publish the changes made on CRM. When I try do this in Deploy Manager I get the follow error: ---------------------------------------------------------------------------- ----- Publish done with errors. See the event log to get deitails NETRA-INOVACAO: ***Error*** Failed to download XSL template files from Web Server ---------------------------------------------------------------------------- ----- Can somebody help me? I don't know if the migration process have any relationship with the error. Thank you for pay attention. []'s Vin´┐Żcius Pitta...

Money 2007 and investments
I recently changed to Money 2007 Deluxe. I have some investments at a certain company. There are three different accounts with this company. When trying to set this up, I entered one under the "new investments" tab and used the drop-down list in Money to select the company name. Later, I changed the account's name to "XXX investment at "YYY" company (I intended to do the same with the other two accounts). No problem there. However, when I tried to enter the second account from this same company, I got a dialog box stating that I already had an investme...

more on VBA function name change
I thought I'd start a new thread since I haven't received any replies to my first one... To recap: I've declared a function in a module using mixed case: Function TMDE_Category (FormName As Form) I noticed recently that it appeared in the module as Function tmde_category(FormName As Form) I changed it back to the mixed case declaration, saved the module, exited the app, reopened it and looked. The function had changed back to the all lowercase declaration. Things I've tried since the original post: Using the databse documenter, I selected all ob...

How to change icon for my application
Hi, I am currently developing an application on visual studio 6.0, and i wish to change the MFC icon on my application header. Anyone can help? Thank you. Raed Sawalha wrote: > Hi, I am currently developing an application on visual studio 6.0, and i > wish to change the MFC icon on my application header. Anyone can help? Thank > you. > > Open the icon resource for editing by double clicking. Then notice the control just above the editing grid that lets you switch between editing the large icon and editing the small one. -- Scott McPhillips [VC++ MVP] thanx that work...

How to change newsgroup message font
Like many other ribbon based programs I sometimes struggle to find how to make a change. This time its how to change the font just for newsgroup messages? regards "nobody" wrote in message news:EWTao.39493$GF5.7129@hurricane... > Like many other ribbon based programs I sometimes struggle to find how to make a change. This time its how to change the font just for newsgroup messages? Newsgroup messages are usually plain text. The font used is that selected at [no name tab] > Options > Mail > Read > Fonts for the encoding specified for the messag...

How do I replace the last entire word in text cells?
I understand the REPLACE command but it seems restricted to characters or bytes. I this case, I want to replace the last word in all cells but the word is always different (ie. varying number of characters). Thanks in advance! Array entered (CTRL+SHIFT+ENTER), this will work: =LEFT(A1,LEN(A1)-MATCH(" ",MID(A1,LEN(A1)-ROW(INDIRECT("1:"&LEN(A1)))+1,1),0)) Change the reference to A1 to which ever cell you want. -- Regards, Dave "George" wrote: > I understand the REPLACE command but it seems restricted to characters or > bytes. I this case, I wan...

Cannot open file after installing Office 2007 Service Pack 2
I cannot open the publisher files after I installed Office 2007 Service Pack 2. Does anybody know what to do? Luckily one of our PCs has not yet the SP2. this way I can at least work. Thanks for help Stefan Are you getting an error? You may have to do a registry fix: Error message when you try to open a publication in Publisher: "Publisher cannot open the file" or "Publisher has detected a problem http://support.microsoft.com/kb/928890/en-us Do you have Norton? How to use Office programs with the Norton AntiVirus Office plug-in http://support.microsoft.com/kb/329820/en-us ...

Notify change of email address when changing ISP
How do I notify my entire address book of an email address when I change ISP's? Thanks By sending a mail to everyone ? If you do so, please use BCC for the adresses, this way you won't spread everybody's e-mail adres to everybody. Niels Bob Baker wrote: > How do I notify my entire address book of an email address when I change ISP's? > Thanks ...

Change a formula to an acual number
I want to change the formula I have created to the number it has created Example: Cell A1 is the number 1. Cell A2 is the formula =a1+1 creatin the number 2. I want this to be a two not a formula. Any ideas? Laura, copy, then paste special, valves -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2000 & 97 ** remove news from my email address to reply by email ** "Laura" <anonymous@discussions.microsoft.com> wrote in message news...

Running Excel 2000 & 2007 Bug
This is a multi-part message in MIME format. ------=_NextPart_000_000C_01CA53A0.C4136A80 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am able to run 2000 and 2007 on the same machine ok except for the = following The File Type associations are messed up. I have a bunch of files that = were created in 2000 and they have the *.xls extension. I want these = files(when double clicked) to open in Excel 2000. However, Excel 2007 = is dominating this action. I have tried changing the association for the *.xls file type to version = 200...

Problem Changing an Investment Name
I am trying to change an investment name and Money 2006 tells me "The name or symbol 'TRP Spectrum Income' has already been used for a deleted investment. Please enter a different name." When I go to delete investments the name does not appear! Any ideas on how I get Money to accept the name change? This is the first time I have run into this situation and I have made numerous name changes in Money over the years. In microsoft.public.money, Ken wrote: >I am trying to change an investment name and Money 2006 tells me "The name >or symbol 'TRP Spec...

Transferring data IN VBA between workbooks
I need to transfer a range of cells for every row one by one from one file File1.xls to a second file File2.xls from within a VBA program. I had it running where it coded a cut and paste but the program runs for 3 hours and If I tried to do anything else where I cut and paste I would get data from my running program when I tried to paste. Is there any way I can do this other than cut and paste ? Dennis I foud out what I was doing wrong I had this Range("A1") = Range("A1:P1") which will work in a single workbook but to a separate workbook you have to put Range("...

Empty Custom Dynamic Dist. Group
Hi all, We are currently trying to finalize our Exchange 2007 deployment but have hit a few problems we can't figure out. The main problem is empty dynamic distribution groups (setup to use a custom filter) I run the following PS command; set-dynamicdistributiongroup -Identity 'AllStaff' -RecipientFilter {(Description -eq 'Staff User' -or Description -eq 'System Administrators')} The command completes without errors but there are no users in this distribution group when I view its members in OWA.. I have copied the msExchDynamicDLFilter property to ADUC Saved...

Appendices Struggles in Word 2007
I'm using Word 2007. I'm using the built-in Heading styles to create sections and subsections for display in the TOC. Each section starts with "# Title." For example, the third section displays as "3 Message Formats." The last two sections are Appendices. I don't want them to display as "10 Appendix" and "11 Appendix," just "Appendix A" and "Appendix B." I can do this for the first headings, but I can't get the subsections (2-4 levels below this first headings) to work. I've read through Shau...

Should I change this code?
Should I change 556 to 560???..............Thanks for your help..........Bob Private Sub Command560_Click() On Error GoTo Err_Command556_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = "frmClientInfomation" DoCmd.OpenForm stDocName, , , stLinkCriteria Exit_Command556_Click: Exit Sub Err_Command556_Click: MsgBox Err.Description Resume Exit_Command556_Click End Sub On Sun, 15 Jul 2007 16:37:26 +1200, "Bob V" <rjvance@ihug.co.nz> wrote: > >Should I change 556 to 560???..............Thanks for your help.....

Outlook and Word 2003 editing and error problem
This is a problem happened on a company PC that IT controls the updates (security, anti-virus) in the night. One day morning, I started having the problems below. I didn't install anything before, but was sure something was installed by company IT that early morning. I turned off the PC and it was on the next day. problems: 1. I can't use mouse to move the cursor to a specific location in the editing window, but I can on the header (to:, subject). I have to use arrow keys to navigate when editing. 2. I can't launch Word whenever Outlook is open. Once Outlook is quit, Wo...

How to change default font in Outlook 2003
Can someone tell me how to change tthe default font in Outlook 2003 when composing a new email. It always comes up as Times New Roman. I remember somewhere that I specified that Outlook should use Word as the text editor and that seems to be the case. I have Arial as my default font in Word but this seems to make no difference when using Outlook. Hi, Please go to Tools > Setting > Mail Format > Stationery and Fonts > Fonts It's right there :) On 20 Nov 2005 06:28:45 -0800, amarsarit@gmail.com wrote: >Hi, >Please go to Tools > Setting > Mail Format > Statione...

Pasword protected Excel file encrypted, how do I read this file?
I password protected an important file. My husband downloaded the Office 2003 upgrade last night. Now when I try to access the file I get this message...This is an Excel file, I don't know why it looks encrypted or why I can't access it. This file is not in a recognizable format. If you know the file is from another program which is incompatible with Microsoft Office Excel, click Cancel, then open this file in its orginal application. If you want to open the file later in Microsoft office Excel, save it in a format that is compatible, such as text format. If you suspect the...