Word Protect/Unprotect Macro for Forms

C

c_en

Hi.

I have some simple text macros assigned to keyboard shortcuts that need to
be used in a protected form. They look like this:


Sub AR6()
'
' AR6 Macro
' Macro recorded 4/23/2009 by
'
Selection.TypeText Text:="MY TEXT IS HERE "
End Sub


Every time I try to use one of the keyboard shortcuts when the form is
protected, I get a Run Time error.

I believe this is due to the fact that the form is protected. From
searching this forum, I think I need to make use of some unprotect/protect
instructions in the macro. I've tried some of the samples that people have
posted, but since I'm new to VBA, I fail every time.

Can someone hold my hand on this?
 
M

macropod

Hi c_en,

Since you can't select anything other than a formfield in a protected Section of a document protected for forms to create the
selection, unprotecting the document isn't likely to be much help. Instead, you could:
1. Insert a formfield where the text is to be input; or
2. Insert Section breaks either side of the portion ofthe document where you want to be able to modify the text and leave that
Section unprotected.

If you're trying to update a formfield in a protected document, try:
ActiveDocument.FormFields(Selection.Bookmarks(1).Name).Result = "MY TEXT IS HERE"
Do note, though, that there's really no need to select the formfield. Provided you know its name you could use:
ActiveDocument.FormFields("FormFieldName").Result = "MY TEXT IS HERE"
 
C

c_en

Thanks so much for the reply, but I don't follow.

The document I have is a form with many fields on it. The people filling
out this form have a choice of several pre-determined text statements to put
in each field. For ease of entry, these pre-determined statements all have a
keyboard macro assigned to them.

I have protected the form so that it can't 'get screwed up' too bad. People
are able to type text into the form fields manually with no problem, but when
they try to use the keyboard macro, a Run-time error '4605' ensues. (This
method or property is not available because the object refers to a protected
area of the document.)

(I hope I'm explaining this properly- thanks again.)


macropod said:
Hi c_en,

Since you can't select anything other than a formfield in a protected Section of a document protected for forms to create the
selection, unprotecting the document isn't likely to be much help. Instead, you could:
1. Insert a formfield where the text is to be input; or
2. Insert Section breaks either side of the portion ofthe document where you want to be able to modify the text and leave that
Section unprotected.

If you're trying to update a formfield in a protected document, try:
ActiveDocument.FormFields(Selection.Bookmarks(1).Name).Result = "MY TEXT IS HERE"
Do note, though, that there's really no need to select the formfield. Provided you know its name you could use:
ActiveDocument.FormFields("FormFieldName").Result = "MY TEXT IS HERE"

--
Cheers
macropod
[Microsoft MVP - Word]


c_en said:
Hi.

I have some simple text macros assigned to keyboard shortcuts that need to
be used in a protected form. They look like this:


Sub AR6()
'
' AR6 Macro
' Macro recorded 4/23/2009 by
'
Selection.TypeText Text:="MY TEXT IS HERE "
End Sub


Every time I try to use one of the keyboard shortcuts when the form is
protected, I get a Run Time error.

I believe this is due to the fact that the form is protected. From
searching this forum, I think I need to make use of some unprotect/protect
instructions in the macro. I've tried some of the samples that people have
posted, but since I'm new to VBA, I fail every time.

Can someone hold my hand on this?
 
C

c_en

Well, I've figured it out by using the advice here:
http://support.microsoft.com/kb/181108/

My troubles were an errant apostrophe, rendering the line useless.

Thanks.



macropod said:
Hi c_en,

Since you can't select anything other than a formfield in a protected Section of a document protected for forms to create the
selection, unprotecting the document isn't likely to be much help. Instead, you could:
1. Insert a formfield where the text is to be input; or
2. Insert Section breaks either side of the portion ofthe document where you want to be able to modify the text and leave that
Section unprotected.

If you're trying to update a formfield in a protected document, try:
ActiveDocument.FormFields(Selection.Bookmarks(1).Name).Result = "MY TEXT IS HERE"
Do note, though, that there's really no need to select the formfield. Provided you know its name you could use:
ActiveDocument.FormFields("FormFieldName").Result = "MY TEXT IS HERE"

--
Cheers
macropod
[Microsoft MVP - Word]


c_en said:
Hi.

I have some simple text macros assigned to keyboard shortcuts that need to
be used in a protected form. They look like this:


Sub AR6()
'
' AR6 Macro
' Macro recorded 4/23/2009 by
'
Selection.TypeText Text:="MY TEXT IS HERE "
End Sub


Every time I try to use one of the keyboard shortcuts when the form is
protected, I get a Run Time error.

I believe this is due to the fact that the form is protected. From
searching this forum, I think I need to make use of some unprotect/protect
instructions in the macro. I've tried some of the samples that people have
posted, but since I'm new to VBA, I fail every time.

Can someone hold my hand on this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top