J
jlute
I have an AddRow macro that is giving me fits. It works fine in other
templates however I just created a template in which it doesn't
behave. The table has 5 columns and the macro is supposed to prompt
to
add another row per the Exit of a prticular field control. If
affirmed
the new row is created with the appropriate control fields and then
the cursor to go to the first field in the first column of the added
row. Everything works fine except the cursor ends up in the second
column. I can't see why this is. Can anyone help? Thanks much in
advance!
Sub AddRow()
'
' AddRow Macro
'
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 oRowID As Long
Dim i As Long
If MsgBox("Do you want to add another row?", vbQuestion + vbYesNo,
"Add Another 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
oRowID = pTable.Rows.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 & "_" & oRowID
.Execute
End With
Next
If Not bCalcFlag Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields,
NoReset:=True
End If
pTable.Rows.Last.Cells(1).Range.Fields(1).Result.Select
End If
End Sub
templates however I just created a template in which it doesn't
behave. The table has 5 columns and the macro is supposed to prompt
to
add another row per the Exit of a prticular field control. If
affirmed
the new row is created with the appropriate control fields and then
the cursor to go to the first field in the first column of the added
row. Everything works fine except the cursor ends up in the second
column. I can't see why this is. Can anyone help? Thanks much in
advance!
Sub AddRow()
'
' AddRow Macro
'
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 oRowID As Long
Dim i As Long
If MsgBox("Do you want to add another row?", vbQuestion + vbYesNo,
"Add Another 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
oRowID = pTable.Rows.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 & "_" & oRowID
.Execute
End With
Next
If Not bCalcFlag Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields,
NoReset:=True
End If
pTable.Rows.Last.Cells(1).Range.Fields(1).Result.Select
End If
End Sub