I haven't tested your code. I am suggesting, that with the macros I sent you
also in your module,
UnProtectDocumentMacro
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
ProtectDocumentMacro
I put fields or table rows into AutoText and insert the AutoText instead of
trying to create fields on the fly. If I want to change the fields, I change
the AutoText manually. Perhaps a kludge but it works for me. What follows is
from a protected form that has different tables that have different kinds of
information and use some different fields. It is to insert a new row above
the current row (forgot to put something in the proper order and want to fix
it). It shows how to insert the AutoText. Maybe this will be of help for
you.
Sub InsertRowAboveMe()
'
' InsertRowAboveMe Macro
' Macro written 12/01/03 by Charles Kyle Kenyon
'
' Unprotect document
UnprotectDocumentMacro
'
'
Dim sAutoTextEntry1 As String
Dim sAutoTextEntry2 As String
Dim oTemplate As Template
Set oTemplate = Templates(ThisDocument.FullName)
'
With Selection
.SelectRow
' Test for Table 2
' -------------------------Table 2 - Time -----------------
If ActiveDocument.Range(0,
Selection.Tables(1).Range.End).Tables.Count = 2 Then
' Test for time row (4 columns)
If .Columns.Count = 4 Then
'
'' Add row if in a table
' If Selection.Information(wdWithInTable) = True Then
' Selection.Rows.Add BeforeRow:=Selection.Rows(1)
' End If
.InsertRows 1
.HomeKey Unit:=wdLine
Application.DisplayAutoCompleteTips = True
With AutoCorrect
.CorrectInitialCaps = True
.CorrectSentenceCaps = True
.CorrectDays = True
.CorrectCapsLock = True
.ReplaceText = True
End With
oTemplate.AutoTextEntries("zDateField").Insert Where _
:=.Range
.MoveRight Unit:=wdCell
oTemplate.AutoTextEntries("zTimeDescription").Insert _
Where:=.Range
.MoveRight Unit:=wdCell
oTemplate.AutoTextEntries("zTimeOutOfCourt").Insert _
Where:=.Range
.MoveRight Unit:=wdCell
oTemplate.AutoTextEntries("zTimeInCourt").Insert _
Where:=.Range
.MoveLeft Unit:=wdCell
.MoveLeft Unit:=wdCell
.MoveLeft Unit:=wdCell
End If ' 4 Columns
End If ' Table 2
'
' Test for Table 3
' -------------------------Tables 3 & 4 -
Disbursements ----------------------
If ActiveDocument.Range(0,
Selection.Tables(1).Range.End).Tables.Count > 2 Then
If ActiveDocument.Range(0,
Selection.Tables(1).Range.End).Tables.Count = 3 Then
sAutoTextEntry1 = "zExpenseDescription"
sAutoTextEntry2 = "zExpenseAmount"
Else ' Table 4 - Payments
sAutoTextEntry1 = "zPaymentDescription"
sAutoTextEntry2 = "zPaymentAmount"
End If
' Test for entry row (3 columns)
If .Columns.Count = 3 Then
'
'' Add row if in a table
' If Selection.Information(wdWithInTable) = True Then
' Selection.Rows.Add BeforeRow:=Selection.Rows(1)
' End If
.InsertRows 1
.HomeKey Unit:=wdLine
Application.DisplayAutoCompleteTips = True
With AutoCorrect
.CorrectInitialCaps = True
.CorrectSentenceCaps = True
.CorrectDays = True
.CorrectCapsLock = True
.ReplaceText = True
End With
oTemplate.AutoTextEntries("zDateField").Insert Where _
:=.Range
.MoveRight Unit:=wdCell
oTemplate.AutoTextEntries(sAutoTextEntry1).Insert _
Where:=.Range
.MoveRight Unit:=wdCell
oTemplate.AutoTextEntries(sAutoTextEntry2).Insert _
Where:=.Range
.MoveLeft Unit:=wdCell
.MoveLeft Unit:=wdCell
End If ' 3 Columns
End If ' Table 3
End With ' Selection
ProtectDocumentMacro
End Sub
Hope this is of some help.
--
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
See also the MVP FAQ:
http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
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.
als0107 said:
Please forgive my ignorance, but I have no idea what I am supposed to do
with this. Do I Type all of it at the beginning of the macro?
The problem with the macro seems to be the third line. I think this is
where I highlighted the part to copy.