A
Angyl
I found this code here on the board that more or less does exactly what I
want (insert a new row of fields in a table if you want it to), but I have a
problem with it:
Sub addrow()
response = MsgBox("Add new row?", vbQuestion + vbYesNo)
If response = vbYes Then
ActiveDocument.Unprotect
Selection.InsertRowsBelow 1
Selection.Collapse (wdCollapseStart)
myRow = Selection.Information(wdStartOfRangeRowNumber)
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Name = "text1row" & myRow
.Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Name = "text2row" & myRow
.Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Name = "tex3row" & myRow
.Enabled = True
.ExitMacro = "addrow"
End With
myNewField = "text1row" & myRow
ActiveDocument.Protect NoReset:=True,
Type:=wdAllowOnlyFormFields
ActiveDocument.Range.FormFields(myNewField).Select
End If
End Sub
~~~~~~
The problem is that if I add other text fields to the document (and I need
to) there is an error with that last line:
ActiveDocument.Range.FormFields(myNewField).Select
I don't understand it. It takes the extra named form field I had in the
document and renames it, then there is the error. I've tried reading the
code to understand what it's doing but I'm boggled. Help?
Question 2:
The field to which I am adding this macro calculates figures from other
fields in its row. How would I modify the code to ADD that calculation for
the figures in ITS row the same way it's adding the macro?
want (insert a new row of fields in a table if you want it to), but I have a
problem with it:
Sub addrow()
response = MsgBox("Add new row?", vbQuestion + vbYesNo)
If response = vbYes Then
ActiveDocument.Unprotect
Selection.InsertRowsBelow 1
Selection.Collapse (wdCollapseStart)
myRow = Selection.Information(wdStartOfRangeRowNumber)
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Name = "text1row" & myRow
.Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Name = "text2row" & myRow
.Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Name = "tex3row" & myRow
.Enabled = True
.ExitMacro = "addrow"
End With
myNewField = "text1row" & myRow
ActiveDocument.Protect NoReset:=True,
Type:=wdAllowOnlyFormFields
ActiveDocument.Range.FormFields(myNewField).Select
End If
End Sub
~~~~~~
The problem is that if I add other text fields to the document (and I need
to) there is an error with that last line:
ActiveDocument.Range.FormFields(myNewField).Select
I don't understand it. It takes the extra named form field I had in the
document and renames it, then there is the error. I've tried reading the
code to understand what it's doing but I'm boggled. Help?
Question 2:
The field to which I am adding this macro calculates figures from other
fields in its row. How would I modify the code to ADD that calculation for
the figures in ITS row the same way it's adding the macro?