Microsoft Office Tutorials and References
In Depth Information
Forms: Deleting a Table Row
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)¶
'Store the list of original field names¶
'in an array so that we can check against it¶
'for the field names used in any calculations¶
nrFields = rng.FormFields.Count¶
ReDim aFieldNames(nrFields)¶
For counter = 1 To nrFields¶
aFieldNames(counter - 1) = rng.FormFields(counter).Name¶
Next counter¶
'Add the increment to the field names, and to¶
'the field names in any calculation¶
'Have run through from back to front because¶
'executing the dialog box to force update¶
'of the .Default property recreates the form field¶
For counter = nrFields To 1 Step -1¶
Set ffld = rng.FormFields(counter)¶
ffld.Name = ffld.Name & "_" & CStr(increment)¶
If ffld.TextInput.Valid Then¶
If ffld.TextInput.Type = wdCalculationText Then¶
ChangeCalculationCode ffld, increment, aFieldNames()¶
End If¶
End If¶
Next counter¶
doc.Protect Type:=wdAllowOnlyFormFields, noreset:=True,
End Sub¶
Search JabSto ::

Custom Search