View Single Post
  #4   Report Post  
Posted to microsoft.public.word.tables
ross ross is offline
external usenet poster
 
Posts: 20
Default Tables in Word - Adding rows to forms

I figured this out by playing around a bit. The below code will create a new
row in a table with the same field types. So if the table contain text, drop
down or check boxs does not matter. It also brings in all the selection
options from the drop down and set it to the first item in the drop down.

Sub addrow3()
' Macro created 04/07/03 by Ross Vanevenhoven
' To add a new row to a table containing text, Drop Down or Check formfields
in every column
' automatically on exit from the last cell in the present last row of the
Table
Dim rownum As Integer, i As Integer
response = MsgBox("Do you need another row?", 36, "Add Row")
If response = vbYes Then
ActiveDocument.Unprotect
With Selection.Tables(1)
FormFieldsCount = .Range.FormFields.Count
.Rows.Add
rownum = .Rows.Count
For i = 1 To .Columns.Count
Select Case .Range.FormFields(i).Type
Case wdFieldFormTextInput
.Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum,
i).Range, Type:=wdFieldFormTextInput
Case wdFieldFormDropDown
.Cell(rownum - 1, i).Range.Copy
.Cell(rownum, i).Range.Paste
.Range.FormFields(FormFieldsCount + i).DropDown.Value = 1
Case wdFieldFormCheckBox
.Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum,
i).Range, Type:=wdFieldFormCheckBox
End Select
Next i
.Cell(.Rows.Count, 1).Range.FormFields(1).Select
.Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro =
"addrow3"
End With
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub