First you need to save the AutoText entry. This would be a row of your table
containing your form fields. I don't think this can be done in a protected
form, so you would need to unprotect the form.
I don't know what an AutoText control is.
The following macro inserts the AutoText entry "MyRow" at the end of table
1. In Word 2003 this adds a row when the AT entry is a table row. When the
macro finishes, your form is protected and the first field in the new row is
selected. I believe different techniques would be required for Word 97, and
possibly Word 2000.
Note, you need to give the macro the name of your AutoText entry, which must
be stored in your template, the number of the table, and the protection
password. These are set as variables to ease changing them in the code.
Sub InsertATRow()
'
' InsertATRow Macro
' Macro written 7/7/2006 by Charles Kyle Kenyon
'
' Declare variables
Dim iRows As Integer
Dim iTable As Integer
Dim sPassword As String
Dim sATEntry As String
' Pick table, set AT entry name and assign password
iTable = 1
sATEntry = "MyRow"
sPassword = "mypass"
' Unprotect Document using subroutine
UnprotectDocumentMacro (sPassword)
' Select Table
ActiveDocument.Tables(iTable).Select
' Move past table to insertion point
Selection.MoveDown Unit:=wdLine, Count:=1
' Insert AutoText entry - will generate error if entry does not exist
ActiveDocument.AttachedTemplate.AutoTextEntries(sATEntry).Insert _
Where:=Selection.Range, RichText:=True
' Get number of rows in table so we can pick the last one
iRows = ActiveDocument.Tables(iTable).Rows.Count
' Select new row
ActiveDocument.Tables(iTable).Rows(iRows).Select
ProtectDocumentMacro (sPassword)
End Sub
Sub UnprotectDocumentMacro(Optional sPassword As String)
' Unprotect document
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect Password:=sPassword
End If
End Sub
Sub ProtectDocumentMacro(Optional sPassword As String)
If ActiveDocument.ProtectionType <> wdAllowOnlyFormFields Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
noreset:=True, Password:=sPassword
End If
End Sub
--
Charles Kenyon
Word New User FAQ & Web Directory:
http://addbalance.com/word
Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
http://addbalance.com/usersguide
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.