L
LPS
Working with Word 2000, I have a macro / form field problem which I hope I
explain clearly...
I have a macro that someone kindly gave me which is intended to add rows to
a table within a form. Upon exiting the last field in the last column of a
row, a new row in meant to be added which copies the form fields from the
current row into the new row, with all of their attributes.
Within the first row of form fields, there are three columns, each of which
contains a unique form field. The first is a generic text field, the second
is a drop-down list and the third is another generic text field. The macro
creates a new row with generic text fields; it does not copy / continue the
drop-down field in the second column. I need it to do this. The macro is
listed at the end of this post.
I am not very knowledgeable about macros so please bare with me; I am not
sure what the macro below is doing but can it be modified so that each of
the three form fields repeat in subsequent rows? Any and all help is hugely
appreciated. Cheers.
Sub addrow()
Dim rownum As Long, i As Long
Dim oRng As Word.Range
Dim oTbl As Table
Set oTbl = Selection.Tables(1)
ActiveDocument.Unprotect
oTbl.Rows.Add
rownum = oTbl.Rows.Count
For i = 1 To oTbl.Columns.Count
Set oRng = oTbl.Cell(rownum, i).Range
oRng.Collapse wdCollapseStart
ActiveDocument.FormFields.Add Range:=oRng, _
Type:=wdFieldFormTextInput
Next i
oTbl.Cell(oTbl.Rows.Count, oTbl.Columns.Count).Range.FormFields(1).ExitMacro
= "addrow"
oTbl.Cell(oTbl.Rows.Count, 1).Range.FormFields(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
explain clearly...
I have a macro that someone kindly gave me which is intended to add rows to
a table within a form. Upon exiting the last field in the last column of a
row, a new row in meant to be added which copies the form fields from the
current row into the new row, with all of their attributes.
Within the first row of form fields, there are three columns, each of which
contains a unique form field. The first is a generic text field, the second
is a drop-down list and the third is another generic text field. The macro
creates a new row with generic text fields; it does not copy / continue the
drop-down field in the second column. I need it to do this. The macro is
listed at the end of this post.
I am not very knowledgeable about macros so please bare with me; I am not
sure what the macro below is doing but can it be modified so that each of
the three form fields repeat in subsequent rows? Any and all help is hugely
appreciated. Cheers.
Sub addrow()
Dim rownum As Long, i As Long
Dim oRng As Word.Range
Dim oTbl As Table
Set oTbl = Selection.Tables(1)
ActiveDocument.Unprotect
oTbl.Rows.Add
rownum = oTbl.Rows.Count
For i = 1 To oTbl.Columns.Count
Set oRng = oTbl.Cell(rownum, i).Range
oRng.Collapse wdCollapseStart
ActiveDocument.FormFields.Add Range:=oRng, _
Type:=wdFieldFormTextInput
Next i
oTbl.Cell(oTbl.Rows.Count, oTbl.Columns.Count).Range.FormFields(1).ExitMacro
= "addrow"
oTbl.Cell(oTbl.Rows.Count, 1).Range.FormFields(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub