Microsoft Office Tutorials and References
In Depth Information
Forms: Inserting a New Table Row
'Make sure user can't accidentally delete¶
'any rows at the end, such as a totals row¶
'nor the last remaining "data row" in table¶
totalRows = rng.Tables(1).Rows.Count¶
If rng.Rows(1).Index <= totalRows - EndRowsIndex _¶
And totalRows > StartRowIndex + EndRowsIndex Then¶
Set doc = rng.Parent¶
If doc.ProtectionType <> wdNoProtection Then¶
doc.Unprotect password:=password¶
End If¶
doc.Protect Type:=wdAllowOnlyFormFields, _¶
noreset:=True, password:=password¶
End If¶
End If¶
End Sub¶
Follow these steps:
1. In Word's VBE, once you have copied the InsertNewTableRow macro
code into a module, change the Const values at the top to fit how the
table is constructed, as follows:
If the form contains more than one table, enter the
number of the table on which the code should
execute (1 for the first table, 2 for the second, and
so on).
AutoTextName The name of the AutoText entry containing the
basic data row.
EndRowsIndex If the table has rows beneath the data rows (a
totals row, such as in the example), enter the
number of such rows. All new rows will be inserted
immediately before these end rows.
If the form is protected with a password, supply it
here. In order to insert the AutoText entry, the
macro needs to unprotect the form. The password is
then used when protecting the form again.
2. Create a toolbar button for this macro, and be sure to save the change
in this template (Tools | Customize | Commands, the Macros category).
3. Finish setting up the form and then protect it.
4. Set up the form and the basic table—a header row, if needed, and at
least one "data row" containing form fields that will be repeated.
Search JabSto ::

Custom Search