T
Tonya Marshall
I've constructed a form that the user can add rows to a table if more
are needed. The macro unlocks the form, goes to a bookmark and adds
another row and then form text fields are added to each of 8 columns,
the form is relocked and the cursor sits at the beginning of the row at
the first text field. I had to use a keyboard macro to add the text
fields and would like to shorten it up to a few lines of code that adds
text fields to the 8 columns and then rests on the right side of the
last text field so that the bookmark can be repositioned to sit in the
last row. Here is the code minus a lot of the text field addition
lines. That area in question is separated by double paragraphs.
Sub AddRow()
Set aDoc = ActiveDocument
If aDoc.ProtectionType <> wdNoProtection Then
aDoc.Unprotect
End If
ActiveDocument.Bookmarks("AddRow").Select
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="AddRow"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.SelectRow
Selection.MoveLeft Unit:=wdCharacter, Count:=1
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub
Thanks
are needed. The macro unlocks the form, goes to a bookmark and adds
another row and then form text fields are added to each of 8 columns,
the form is relocked and the cursor sits at the beginning of the row at
the first text field. I had to use a keyboard macro to add the text
fields and would like to shorten it up to a few lines of code that adds
text fields to the 8 columns and then rests on the right side of the
last text field so that the bookmark can be repositioned to sit in the
last row. Here is the code minus a lot of the text field addition
lines. That area in question is separated by double paragraphs.
Sub AddRow()
Set aDoc = ActiveDocument
If aDoc.ProtectionType <> wdNoProtection Then
aDoc.Unprotect
End If
ActiveDocument.Bookmarks("AddRow").Select
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="AddRow"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.SelectRow
Selection.MoveLeft Unit:=wdCharacter, Count:=1
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub
Thanks