TextBox in protected document

  • Thread starter Thread starter sun tea
  • Start date Start date
S

sun tea

Hi

I have a document with two sections. The upper section has shapes on it and some controls that modify the shapes with VBA. The lower part of the document has a form on it and is protected for form editing only. I added a continuous section to separate the two sections of my form and have section 2 that has the form selected in the document protection.

I also have a text box in the Header of the document that is being changed with VBA when the shapes in the first section change. When I start protection on the document the text box in the header area is no longer editable.

I use the following code to change the text box in the header area.

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes(TITLE_TEXT_BOX_NAME).TextFrame.TextRange.Text = "some text"

When I protect the document applying protection to section 2 only this lineof code generates an error saying the document is protected.

Any help would be appreciated.

Thanks

Sun Tea
 
Editing is limited in a protected document; this includes any unprotected
sections. You probably have to unprotect and reprotect the document, which you
can do in code, before you can add text to the header.

By the way, to which header in which section is the text box anchored?
 
Hi Stephen

Thank you so much for your reply.
Unprotecting the document with Code worked.

I am guessing the text box is in the header of the first section because the code to change it is ActiveDocument.Sections(1).Headers ...

Basically what I have is a one page document with graphics and text boxes in the header and footer. I have the body of the of the document divided into two sections; one for displaying sets of shapes and one for a User Form.

Some of the shapes I have in the first section are in the story area (I think that is what it is called, the header type area behind the section) of the first section and the VBA code changes those shapes and text boxes just fine without unprotecting the document. It was just the text box in the header of the page/document that was being affected by the document protection.

Also I would very much like to protect the header, footer, and story areas of the document so they can not be accessed by the user. Is there any way of doing that?

Thanks and Best Regards

Sun Tea
 
Are the headers unlinked? Otherwise, you have the same text box in both
sections, and that's probably what's causing the error message.

I'm not sure what you mean by "story area"; usually, the space for ordinary text
is called the "main body" and other areas, such as headers and footers, are
referred to as "story ranges" (at least that's the terminology in Word VBA).

Document protection should prevent users from changing content. Whenever you
want to enforce changes, using a macro that unprotects and reprotects the
document should work. In fact, that's the way it is done in a macro that enables
spell-checking in a protected document:
http://word.mvps.org/faqs/macrosvba/SpellcheckProtectDoc.htm.

--
Stefan Blom
Microsoft Word MVP
 
Yeah the using VBA to unprotect/protect worked to change the data in the text box. I am not quite sure what I am talking about either ;) but basicallyI have only one page in the document and I used a continuous break to create the two sections in the document. The header area is being used to store data, graphics, and shapes and it extends the entire document to the footer. I had no trouble changing some of the shapes lines etc in the header area just the text box was giving me trouble.

Thanks so much for you help. Now also I see that the header/footer area isalso not protected against editing.

Best Regards

Sun Tea
 
It seem like the entire document is now protected and not just the section with the form on it. I selected the section with the form on it when protecting the document. Is there any way to restrict protection to just one section and also to just the header/footer area?

Thanks

Sun Tea
 
Actually from what I can see the form section is locked for form editing only and the first section is open for editing except the shapes are locked and can not be selected or deleted. Also the header/footer area is locked. So I think this is close to what I am looking for.

Thanks for your help.

Sun Tea
 
Back
Top