Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TextBox in protected document

146 views
Skip to first unread message

sun tea

unread,
Jun 25, 2012, 5:47:07 AM6/25/12
to
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 line of code generates an error saying the document is protected.

Any help would be appreciated.

Thanks

Sun Tea

Stefan Blom

unread,
Jun 25, 2012, 10:19:31 AM6/25/12
to
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?

--
Stefan Blom
Microsoft Word MVP





"sun tea" <scrip...@gmail.com> wrote in message
news:bf62917a-cf57-45ba...@googlegroups.com...

sun tea

unread,
Jun 25, 2012, 12:40:22 PM6/25/12
to
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

On Monday, June 25, 2012 9:19:31 AM UTC-5, Stefan Blom wrote:
> 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?
>
> --
> Stefan Blom
> Microsoft Word MVP
>
>
>
>
>
> "sun tea" wrote in message

Stefan Blom

unread,
Jun 25, 2012, 3:34:50 PM6/25/12
to
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





"sun tea" <scrip...@gmail.com> wrote in message
news:afe87c20-6ed5-407e...@googlegroups.com...

sun tea

unread,
Jun 25, 2012, 8:44:14 PM6/25/12
to

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 basically I 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 is also not protected against editing.

Best Regards

Sun Tea



On Monday, June 25, 2012 2:34:50 PM UTC-5, Stefan Blom wrote:
> 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
>
>
>
>
>
> "sun tea" wrote in message

sun tea

unread,
Jun 25, 2012, 8:49:59 PM6/25/12
to
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

sun tea

unread,
Jun 25, 2012, 11:06:06 PM6/25/12
to
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

Stefan Blom

unread,
Jun 26, 2012, 1:19:05 PM6/26/12
to
I'm glad you got it sorted.

--
Stefan Blom
Microsoft Word MVP





"sun tea" <scrip...@gmail.com> wrote in message
news:34a697ed-853b-4683...@googlegroups.com...
0 new messages