F
FredEp57
I have some code (attached at the end of this question). However, I cannot
figure out how to keep this from adding a row if I use the mouse to click
into another form field.
Any help would be appreicated.
Attached code
===========================
Sub add2()
' Copying the last row in its entirety to a newly created row is
trivial:
' however, getting the correct parts and pieces are more complicated
Dim rownum, colnum As Integer
Dim mRow, mCol, i, j As Integer
Dim mVar As String
' First check that you are using a document not at template.
If ActiveDocument.Name = ActiveDocument.AttachedTemplate Then
MsgBox "You're trying to write to the template"
End
End If
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect 'Password:="pass",
End If
mRow = Selection.Tables(1).Rows.Count
With Selection.Tables(1)
.Rows(.Rows.Count).Range.Copy
.Rows(.Rows.Count).Range.Paste
End With
For j = 1 To Selection.Tables(1).Columns.Count
Select Case Selection.Tables(1).Cell(i, j).Range.FormFields(1).Type
Case wdFieldFormTextInput
Selection.Tables(1).Cell(i, j).Range.FormFields(1).Result = ""
Case wdFieldFormDropDown
Case wdFieldFormCheckBox
End Select
Next j
iRows = Selection.Tables(1).Rows.Count
iCols = Selection.Tables(1).Columns.Count
iUpOneRow = iRows - 1
Selection.Tables(1).Cell(iUpOneRow, iCols).Range.FormFields(1).ExitMacro
= ""
Selection.Tables(1).Cell(iRows, iCols).Range.FormFields(1).ExitMacro =
"add2"
Selection.Tables(1).Cell(Selection.Tables(1).Rows.Count,
1).Range.FormFields(1).Select
ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields
'Password:="pass",
End Sub
=======================================
figure out how to keep this from adding a row if I use the mouse to click
into another form field.
Any help would be appreicated.
Attached code
===========================
Sub add2()
' Copying the last row in its entirety to a newly created row is
trivial:
' however, getting the correct parts and pieces are more complicated
Dim rownum, colnum As Integer
Dim mRow, mCol, i, j As Integer
Dim mVar As String
' First check that you are using a document not at template.
If ActiveDocument.Name = ActiveDocument.AttachedTemplate Then
MsgBox "You're trying to write to the template"
End
End If
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect 'Password:="pass",
End If
mRow = Selection.Tables(1).Rows.Count
With Selection.Tables(1)
.Rows(.Rows.Count).Range.Copy
.Rows(.Rows.Count).Range.Paste
End With
For j = 1 To Selection.Tables(1).Columns.Count
Select Case Selection.Tables(1).Cell(i, j).Range.FormFields(1).Type
Case wdFieldFormTextInput
Selection.Tables(1).Cell(i, j).Range.FormFields(1).Result = ""
Case wdFieldFormDropDown
Case wdFieldFormCheckBox
End Select
Next j
iRows = Selection.Tables(1).Rows.Count
iCols = Selection.Tables(1).Columns.Count
iUpOneRow = iRows - 1
Selection.Tables(1).Cell(iUpOneRow, iCols).Range.FormFields(1).ExitMacro
= ""
Selection.Tables(1).Cell(iRows, iCols).Range.FormFields(1).ExitMacro =
"add2"
Selection.Tables(1).Cell(Selection.Tables(1).Rows.Count,
1).Range.FormFields(1).Select
ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields
'Password:="pass",
End Sub
=======================================