2 Attachment(s)
Add FormField and Text to text that already Exists in a Table Cell
I have a Word Template that uses VBA to maintain Legacy form fields in over in thousands of documents that are based on that template. The maintenance of the form fields and updating dropdown options works great with this method. However, now I need to add an Active checkbox to the cell in the second table, in the third row, in the second column. I need it to check if the Active checkbox has already been added and only add it if not. I also need it to fill in any value that may be present in the External ID field. The bookmark for the External ID field is "External_ID"
Here's a screenshot of what the impacted section currently looks like.
Attachment 26223
This screenshot is what I need it to look like.
Attachment 26224
I keep running into an issue at the FormFields.Add Range. I just can't get it to add it in the right spot. I also don't know how to get it to only add the Active and the checkbox if the check box is missing.
Please Help.
Code:
Sub AddCheckbox()
Dim ExtID As String, ExtChk As Integer
'
'
'
ExtID = ActiveDocument.FormFields("External_ID").Result
ExtChk = ActiveDocument.FormFields("ExtID_Checkbox").Result
ActiveDocument.Unprotect
With ActiveDocument.Tables(2).Cell(Row:=3, Column:=2).Range
.Delete
.InsertAfter Text:="External ID: "
.MoveEnd Unit:=wdCell, Count:=1
With ActiveDocument.FormFields.Add(Selection.Active, wdFieldFormTextInput)
.Name = "External_ID"
.Result = ExtID
With ActiveDocument.FormFields.Add(Selection.Range, wdFieldFormCheckBox)
.Name = "ExtID_Checkbox"
End With
End With
ActiveDocument.Protect wdAllowOnlyFormFields, True
End Sub
Cheers,
Thyme2Cook