Paul,
This worked marvelously and I understand it. However, in testing, I ran into an issue where some older documents, that were created from earlier versions of the template do not recognize the "External_ID" as a bookmark. The issue went away simply by opening the form field properties box and visually checked that the correct bookmark name was present (it was) and closing without changing anything. I'm concerned that there could be more documents with that same issue. Any ideas as to how to mitigate such an issue if it does arise again?
This is the code that I put into place. I added a check for un-named form fields because they are managed and referenced elsewhere in the code (this is a snippet of the whole code). Since I am adding a new form field the index number for all those fields will change. Do you have any thought on what I have below?
Sub AddCheckbox()
Dim Rng As Range, FmFld As FormField
' Checks for un-named form fields and renames them if they are only referenced by the index number.
With ActiveDocument
If .FormFields.Count = 90 Then
If .Bookmarks.Exists("POI") = False Then
.FormFields(42).Name = "POI"
End If
If .Bookmarks.Exists("State") = False Then
.FormFields(43).Name = "State"
End If
If .Bookmarks.Exists("RSVPReferral") = False Then
.FormFields(44).Name = "Referral"
End If
End If
.FormFields("POI").Enabled = True
.FormFields("Referral").Enabled = True
If .Bookmarks.Exists("Dropdown1") = True Then
.FormFields("Dropdown1").Name = "AddressType"
End If
If .Bookmarks.Exists("Dropdown4") = True Then
.FormFields("Dropdown4").Name = "TC_Name"
End If
.FormFields("Record_Date").TextInput.EditType wdCurrentTimeText, , "M/dd/yyyy h:mm am/pm", False
End With
' Checks for the existence of Active checkbox and adds when necessary.
With ActiveDocument
.Unprotect
With .Tables(2).Cell(3, 2)
.Range.Bold = False
.SetWidth ColumnWidth:=InchesToPoints(2.3), RulerStyle:=wdAdjustFirstColumn
End With
If .Bookmarks.Exists("ExtID_Checkbox") = False Then
Set Rng = .Bookmarks("External_ID").Range
With Rng
.Collapse wdCollapseEnd
.Text = " Active: "
.Collapse wdCollapseEnd
Set FmFld = .FormFields.Add(.Duplicate, wdFieldFormCheckBox)
FmFld.Name = "ExtID_Checkbox"
End With
With .FormFields("ExtID_Checkbox").CheckBox
.AutoSize = False
.Size = 8
End With
End If
End With
End Sub
Thanks,
Thyme2Cook