View Single Post
  #5   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP
 
Posts: n/a
Default Can Word automatically create a new row in a table after data

The following code will add Text FormFields to the first 3 cells and
DropDown FormFields to the cells 4 and 5. You will need to replace the
Item1 through Item5 and ItemA through ItemB with the actual items that you
want in the dropdowns:

Dim rownum As Integer, i As Integer
With ActiveDocument
.Unprotect
.Tables(1).Rows.Add
rownum = .Tables(1).Rows.Count
For i = 1 To 3
.FormFields.Add Range:=.Tables(1).Cell(rownum, i).Range,
Type:=wdFieldFormTextInput
Next i
.FormFields.Add Range:=.Tables(1).Cell(rownum, 4).Range,
Type:=wdFieldFormDropDown
With .Tables(1).Cell(rownum, 4).Range.FormFields(1).DropDown.ListEntries
.Add "Item1"
.Add "Item2"
.Add "Item3"
.Add "Item4"
.Add "Item5"
End With
.FormFields.Add Range:=.Tables(1).Cell(rownum, 5).Range,
Type:=wdFieldFormDropDown
With .Tables(1).Cell(rownum, 5).Range.FormFields(1).DropDown.ListEntries
.Add "ItemA"
.Add "ItemB"
.Add "ItemC"
.Add "ItemD"
.Add "ItemE"
End With
.Tables(1).Cell(rownum, 5).Range.FormFields(1).ExitMacro = "addrow"
.Tables(1).Cell(rownum, 1).Range.FormFields(1).Select
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"joel" wrote in message
...
Doug - First off, thank you very much for your help. I added the
'addrow'
macro to the Text Form Field Options of the last field in the row, and it
does indeed automatically create a new row with new text fields. It
doesn't,
however, reproduce the drop-down field menu. Is there a way to do that as
well?

For example: The row has 5 columns, and 3 of those would be text fields
and
two would be drop down fields. Can those drop-downs be reproduced
automatically in the new row?

(I should point out that I'm very ignorant of macros, so as lay as is gets
in layman's terms would be appropriate here)

Thanks again!