Word - TextBox in protected document

Asked By sun tea on 25-Jun-12 05:47 AM
Hi

I have a document with two sections.  The upper section has shapes on it an=
d some controls that modify the shapes with VBA.  The lower part of the doc=
ument has a form on it and is protected for form editing only.  I added a c=
ontinuous 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 protect=
ion 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 =3D "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 replied to sun tea on 25-Jun-12 10:19 AM
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 replied to Stefan Blom on 25-Jun-12 12:40 PM
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 th=
e code to change it is ActiveDocument.Sections(1).Headers ...

Basically what I have is a one page document with graphics and text boxes i=
n the header and footer.  I have the body of the of the document divided in=
to 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 thi=
nk that is what it is called, the header type area behind the section) of t=
he 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 he=
ader of the page/document that was being affected by the document protectio=
n.

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 o=
f doing that?

Thanks and Best Regards

Sun Tea

=20
h you=20
t and=20
ocument=20
tinuous=20
has=20
ged=20
tection=20
TEXT_BOX_NAME).TextFrame.TextRange.Text=20
line of=20
Stefan Blom replied to sun tea on 25-Jun-12 03:34 PM
Are the headers unlinked? Otherwise, you have the same text box in both
sections, and that is probably what is causing the error message.

I am 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 is 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 is 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 replied to Stefan Blom on 25-Jun-12 08:44 PM
Yeah the using VBA to unprotect/protect worked to change the data in the te=
xt 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 crea=
te the two sections in the document.  The header area is being used to stor=
e data, graphics, and shapes and it extends the entire document to the foot=
er.  I had no trouble changing some of the shapes lines etc in the header a=
rea 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



ry text=20
re=20
A).
you=20
=20
enables=20
e the
es in
into
.
think
the
fine
der of
eas of
of
ted
hich
n it
e
hat has
hanged
e.
LE_TEXT_BOX_NAME).TextFrame.TextRange.Text
is line
sun tea replied to sun tea on 25-Jun-12 08:49 PM
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 prote=
cting the document.  Is there any way to restrict protection to just one se=
ction and also to just the header/footer area?

Thanks

Sun Tea

text box. I am not quite sure what I am talking about either ;) but basical=
ly I have only one page in the document and I used a continuous break to cr=
eate the two sections in the document.  The header area is being used to st=
ore data, graphics, and shapes and it extends the entire document to the fo=
oter.  I had no trouble changing some of the shapes lines etc in the header=
area just the text box was giving me trouble.
is also not protected against editing.
nary text=20
are=20
VBA).
r you=20
he=20
t enables=20
use the
oxes in
d into
rm.
(I think
f the
st fine
eader of
areas of
y of
ected
which
d?
on it
the
a
that has
changed
t
ble.
.
ITLE_TEXT_BOX_NAME).TextFrame.TextRange.Text
this line
sun tea replied to sun tea on 25-Jun-12 11:06 PM
Actually from what I can see the form section is locked for form editing on=
ly and the first section is open for editing except the shapes are locked a=
nd 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


n with the form on it.  I selected the section with the form on it when pro=
tecting the document.  Is there any way to restrict protection to just one =
section and also to just the header/footer area?
e text box. I am not quite sure what I am talking about either ;) but basic=
ally 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 head=
er area just the text box was giving me trouble.
a is also not protected against editing.
th
dinary text=20
s, are=20
d VBA).
ver you=20
the=20
hat enables=20
cause the
boxes in
ded into
Form.
a (I think
of the
just fine
header of
n.
y areas of
way of
otected
t, which
red?
es on it
f the
d a
2 that has
ng changed
art
table.
ea.
(TITLE_TEXT_BOX_NAME).TextFrame.TextRange.Text
y this line
Stefan Blom replied to sun tea on 26-Jun-12 01:19 PM
I am glad you got it sorted.

--
Stefan Blom
Microsoft Word MVP