Microsoft Office Tutorials and References
In Depth Information
Forms: Deleting a 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¶
The following code is included for completeness. The next example details how
it is used.
Option explicit¶
' * * * * *¶
'If the form has more than one table¶
'set this value to the number of the¶
'table to process with this code¶
Const TableIndex As Long = 1¶
'Name of the AutoText entry that contains¶
'the row that should be inserted¶
Const AutoTextName As String = "NewRow"¶
'Enter the number of rows that should remain¶
'below the row being inserted.¶
'For example, this sample table has one row,¶
'the Totals row, that should stay at the end¶
'This and the password constant are shared¶
'with the DeleteCurrentRow macro.¶
Public Const EndRowsIndex As Long = 1¶
'The password to unprotect (leave as is if you're¶
'not assigning a password to the form¶
Public Const password = ""¶
' * * * * *¶
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¶
Search JabSto ::

Custom Search