What is not working?
Code:
Sub CreateTextField()
'With the exception of this minor change you code seems to work fine.
If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect
Dim oRng As Range
Dim aFld As FormField
Set oRng = Selection.Range
With oRng
.End = .Paragraphs(1).Range.End + 1
.Collapse 0
.Text = vbCr
.Collapse 0
Set aFld = .FormFields.Add(Range:=oRng, Type:=wdFieldFormTextInput)
aFld.TextInput.EditType Type:=wdRegularText, Default:="Category", Format:="First capital"
.End = aFld.Range.End
.Font.Bold = True
.Collapse 0
.Text = ": "
.Font.Bold = False
.Collapse 0
Set aFld = .FormFields.Add(Range:=oRng, Type:=wdFieldFormTextInput)
aFld.TextInput.EditType Type:=wdRegularText, Default:="Detail", Format:="First capital"
.End = aFld.Range.End
.Collapse 0
'why do you need this? The bookmarks shouldn't be an issue
'Do While .Paragraphs(1).Range.Bookmarks.Count > 0
' .Paragraphs(1).Range.Bookmarks(1).Delete
'Loop
.Select
End With
lbl_Exit:
Set oRng = Nothing
Set aFld = Nothing
Exit Sub
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub