Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding autotext to protected forms in Word?

Status
Not open for further replies.

IndigoDragon

Programmer
Aug 2, 2005
57
NL
I made a form which I'd like to protect because of text placement etc. However, when a form is protected it is obviously no longer possible to add autotext in the form...

Is there a workaround/sollution to this or is this 'just' a feature I have to content with?

Thanx for any replies!!!
 
There is no direct workaround. There could be some VBA coding that could possibly fire with AutoText - that is, turn protection off for the AutoText entry, then turn it back on again. have not done this, but I think it would be possible.

Gerry
My paintings and sculpture
 

The easiest workaround is to use an Exit Macro and if the AutoText Name (or any other trigger you care to agree with your user) is entered, to replace it with the Autotext entry. As far as I know there is no problem inserting the Autotext into a Formfield with code - you don't need to unprotect the form; it's just that the UI doesn't give the option (I have no idea why).

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Just in case you did not get that, what that means is the user enters the AutoText name into the formfield; the OnExit macro takes whatever is in the formfield and inserts the AutoText based on that.

Tony, I have found a problem with this.

AutoText requires a Where:= and it is a Range. If you use the formfield range itself, then yes, the entered text does become the AutoText entry - assuming of course it IS a valid AutoText.

However, doing so replaces the Range of the formfield. Thus, the text is correct, but the formfield is gone.

This may not be desireable.

The normal Selection.Range for Where:= does insert the AutoText, BUT it inserts it after the entered text. Thus you would have the AutoText Name, followed by the AutoText entry itself. This is not good.

However, this can be fixed with
Code:
Dim strIn As String
strIn = ActiveDocument.FormFields("Text1").Result
NormalTemplate.AutoTextEntries(strIn). _
  Insert Where:=Selection.Range, RichText:=True
' take the NEW Result and remove the le
ActiveDocument.FormFields("Text1").Result = _
  Right(ActiveDocument.FormFields("Text1").Result, Len(strIn))

Gerry
My paintings and sculpture
 
Thanx for your replies!

I'll use writing it to the formfield. I noticed before that the autotext replaces the formfield. This even occurs if you enter it when the doc isn't protected.
I must say that I was surprised by this behaviour. Actyally: all the 'insert' options are disabled when the doc is protected. For the objects that could influence the layout dramatically, like tables or (big) OLE objects, I understand. However, you'd expect the 'text' insertion objects to be available at least... I expected it to be part of the 'in text' level. I really don't think this ads to the productivity and would consider it to be a 'bug'. Good thing to put on the wishlist! (A call to all Office devevlopers!!! ;-))
Anyway, I'll try it out an will let you know how it went. By the way: the autotext is in a custom template that holds the toolbars and autotext, etc. Can I address that the same way as the 'normal' template? Well, I guess I'll know soon enough whn I try it out...so,

cYa + thanx again!
 
Hi Gerry,

These things are certainly perverse!

AFAIK, this works correctly - providing, of course, you want to replace the whole FormField and not just a part of it ...
Code:
NormalTemplate.AutoTextEntries(strIn). _
  Insert Where:=Selection.Bookmarks(1).Range.Fields(1).result, RichText:=True

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top