Insert New Row w/ Form Fields

K

Kerevek

I'm looking for a macro that will create a new row in a protected doc that
copies the last row w/ form fields and place it on the bottom of the table.
Then I can assign it to a button for the user to click when adding additional
rows.
 
D

Doug Robbins - Word MVP

Have the following macro run on exit from the last formfield in the last row
of the table. It will ask the user if they want to add another row.

Sub addrow()
' Macro created 02/02/03 by Doug Robbins
' To add a new row to a table containing 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)
.Rows.Add
rownum = .Rows.Count
For i = 1 To .Columns.Count
ActiveDocument.FormFields.Add Range:=.Cell(rownum, i).Range,
Type:=wdFieldFormTextInput
Next i
.Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro =
"addrow"
.Cell(.Rows.Count, 1).Range.FormFields(1).Select
End With
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If

End Sub


--
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top