View Single Post
  #3   Report Post  
Posted to microsoft.public.word.tables
Greg Maxey
 
Posts: n/a
Default can word automatically create a new row

You might try:

Sub NewRow()
Dim pTable As Word.Table
Dim oRng1 As Word.Range
Dim oRng2 As Word.Range
Dim oRng3 As Word.Range
Dim oFormField As Word.FormField
Dim bCalcFlag As Boolean
Dim i As Long
If MsgBox("Do you want to create a new row?", vbQuestion + vbYesNo,
"Create New Row") = vbYes Then
ActiveDocument.Unprotect
bCalcFlag = False
Set pTable = Selection.Tables(1)
Set oRng1 = pTable.Rows(pTable.Rows.Count).Range
Set oRng3 = oRng1.Duplicate
With oRng1
.Copy
.Collapse Direction:=wdCollapseEnd
.Paste
End With
Set oRng2 = pTable.Rows(pTable.Rows.Count).Range
For i = 1 To oRng1.FormFields.Count
Set oFormField = oRng1.FormFields(i)
With oFormField
If .Type = wdFieldFormTextInput Then
If Not bCalcFlag And .TextInput.Type = 5 Then
bCalcFlag = True
MsgBox "You must edit expressions in any new calculation
fields."
End If
End If
End With
oRng2.FormFields(i).Select
With Dialogs(wdDialogFormFieldOptions)
.Name = oRng3.FormFields(i).Name & "_Copy_" & i
.Execute
End With
Next
If Not bCalcFlag Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End If
End Sub