Microsoft Office Tutorials and References
In Depth Information
Forms: Formatting Text Input in Form Fields
' * * * * *¶
Sub InsertNewTableRow()¶
'Variable declaration¶
Dim doc As Word.Document¶
Dim tmpl As Word.Template¶
Dim tbl As Word.Table¶
Dim lastRow As Long¶
Dim ffldName As String¶
Dim rng As Word.Range¶
Dim ffld As Word.FormField¶
Dim nrFields As Long¶
Dim increment As Long¶
Dim aFieldNames() As String¶
Dim counter As Long¶
Set doc = ActiveDocument¶
Set tmpl = doc.AttachedTemplate¶
Set tbl = doc.Tables(TableIndex)¶
'Calculate the row index after which the¶
'new row should be inserted¶
lastRow = tbl.Rows.Count - EndRowsIndex¶
Set rng = tbl.Rows(lastRow).Range¶
'Calculate the increment number for the new row¶
'by picking up the text to the right of¶
'the underscore just preceding it in the first form field¶
ffldName = rng.FormFields(1).Name¶
increment = CLng(Right(ffldName, _¶
(Len(ffldName) - InStr(ffldName, "_")))) + 1¶
'Collapse range so that newly inserted row¶
'follows immediately after the rng-row¶
rng.Collapse wdCollapseEnd¶
If doc.ProtectionType <> wdNoProtection Then¶
doc.Unprotect password:=password¶
End If¶
Set rng = tmpl.AutoTextEntries(AutoTextName).Insert( _¶
Where:=rng, RichText:=True)¶
'rng.Select¶
'Store the list of original field names¶
'in an array so checking against the array¶
'for the field names used in any calculations¶
'can be done.¶
nrFields = rng.FormFields.Count¶
ReDim aFieldNames(nrFields)¶
For counter = 1 To nrFields¶
aFieldNames(counter - 1) = rng.FormFields(counter).Name¶
Next counter¶
Wrd
Search JabSto ::




Custom Search